Java - Write code to Append correct delimiter to a number th, st, rd returning the number and delimiter appended

Requirements

Write code to Append correct delimiter to a number th, st, rd returning the number and delimiter appended

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        double numVal = 42;
        System.out.println(getStringTH(numVal));
    }//from   ww w. j a  va  2s.  c  o  m

    /**
     * Appends correct delimiter to a number th, st, rd returning the number and
     * delimiter appended
     * 
     * @param numVal
     * @return
     */
    public static String getStringTH(final double numVal) {
        final double remainder = numVal % 10;
        String numth = String.valueOf(numVal);
        if (remainder == 1) {
            numth += "st";
        } else if (remainder == 2) {
            numth += "nd";
        } else if (remainder == 3) {
            numth += "rd";
        } else {
            numth += "th";
        }
        return numth;
    }
}

Related Exercise