Reputation: 39731
Given a number, I'd like to transform it into a string, but insert commas in the thousands place etc, like:
int number = 123456;
String formatted = String.valueOf(number);
println(formatted); // but print "123,456"?
does GWT offer a way of doing this, or should we write our own method?
Thanks
Upvotes: 1
Views: 779
Reputation: 1592
The first one is to format a number with decimal points and include a comma. The other is with out decimal points. I'm giving this out because it wasn't so easy for me to figure it out the first time when I was starting out.
private NumberFormat decFormat = NumberFormat.getFormat("#,##0.00;(#,##0.00)");
private NumberFormat intFormat = NumberFormat.getFormat("#,##0;(#,##0)");
Upvotes: 3