Hi,
How do I create a method that formats a number based on it's
string value ? Lets say I have the number 1027
I want to call my format routine to return ( lets say my locale is set to English US ) 1,027
If I passed 1027.000 to my routine, I want it to return 1,027.000
I have written the following routine to achieve this goal, but for some reason, any number I pass in with trailing zero's get truncated. If I pass in 1027.123, it works fine. If I pass in 1027.000, it returns 1,027 ! Am I missing something basic ?
Here's the snippet :
protected static String embedProperDelim (String s,
int coding) {
java.text.NumberFormat nf = java.text.NumberFormat.getInstance();
Number myNumber = null;
try {
myNumber = nf.parse (s);
} catch (java.text.ParseException e) {
e.printStackTrace ();
}
String formatted = nf.format(myNumber);
return formatted;
}
Any help is much appreciated.