Here you can find the source of formatNumberWithExtension(int num)
Parameter | Description |
---|---|
num | a parameter |
public static String formatNumberWithExtension(int num)
//package com.java2s; /*/*from w w w . ja v a2 s . c o m*/ * DateTimeUtils.java * * Created on March 21, 2008, 9:41 AM * * Copyright 2011 FooBrew, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * * @param num * @return */ public static String formatNumberWithExtension(int num) { int n = num; while (n > 10) n = n % 10; // (1,21,31) st, (2,22) nd, (3,23) rd, (4:20,24:30) th String append = ""; if (n == 1) append = (num == 11 ? "th" : "st"); else if (n == 2) append = (num == 12 ? "th" : "nd"); else if (n == 3) append = (num == 13 ? "th" : "rd"); else append = "th"; return (num + append); } }