• Post Reply Bookmark Topic Watch Topic
  • New Topic

A simple question  RSS feed

 
Sajee Joseph
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
Is there a readymade means to convert a numerical figure such as 199999999
to the format 1,999,999,99

Thanks,
Sajee
[ January 20, 2004: Message edited by: Sajee Joseph ]
 
Ram Mohan
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
easy,
just use the following code....
public String formatNumber(String pattern, double value) {
DecimalFormat myFormat = new DecimalFormat(pattern);
String formattedNumber = myFormat.format(value);
return formattedNumber;
}

public static void main(String[] args) {
FormatNumber m = new FormatNumber();
String formattedNumber = m.formatNumber("###,###",199999999);
}
}
but the format ur trying to obtain is very strange actually....(1,99,999,999 is actually very very strange, where exactly are u trying to put ur commas??? by the 100s or 10s???) if u really want such a custom formatting you might have to do some more reading....
http://java.sun.com/docs/books/tutorial/i18n/format/numberpattern.html
the above link gives more info about the patterns that can be used & may prove useful.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!