MCPcopy Create free account
hub / github.com/PCGen/pcgen / buildNumSuffix

Method buildNumSuffix

code/src/java/plugin/exporttokens/TextToken.java:240–270  ·  view source on GitHub ↗

Build the suffix for the provided number. @param number The number to generate the suffix for. @return The suffix (or an empty string if not a number)

(String number)

Source from the content-addressed store, hash-verified

238 * @return The suffix (or an empty string if not a number)
239 */
240 private static String buildNumSuffix(String number)
241 {
242 String result;
243 int intVal;
244 try
245 {
246 intVal = new BigDecimal(number).intValue();
247 }
248 catch (NumberFormatException e)
249 {
250 // Not a number, so no suffix
251 return "";
252 }
253 if (intVal % 10 == 1 && intVal % 100 != 11)
254 {
255 result = "st";
256 }
257 else if (intVal % 10 == 2 && intVal % 100 != 12)
258 {
259 result = "nd";
260 }
261 else if (intVal % 10 == 3 && intVal % 100 != 13)
262 {
263 result = "rd";
264 }
265 else
266 {
267 result = "th";
268 }
269 return result;
270 }
271
272 /**
273 * Never encode the plain text output

Callers 1

getTokenMethod · 0.95

Calls 1

intValueMethod · 0.80

Tested by

no test coverage detected