Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Formatting numbers...  RSS feed

 
George Larry
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hallo-
I'm trying to display numbers as currency in my jsp so I created a DecimalFormat:
double myMoney = rs.getDouble( "CASH" );
DecimalFormat fNumber = new DecimalFormat( "#.00" );
out.println( "I have $" + fNumber.format( myMoney ) + "<br>" );
This works great, except that some of my numbers grow quite large (when I try to display other peoples money, of course... I rarely get to the left of the decimal with myMoney... woe is me), and I would like to have comma's appear if- and only if- the number reaches the thousands/millions/etc.
I tried to change my format to DecimalFormat( 0,000,000.00 ) but I get numbers like 0,000,032.34 when I do that.
Is there a nice clean way of doing this?
Thanks.
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Replace the zeroes with #. It will suppress the zeroes.
DecimalFormat( #,###,###.00 )
------------------
Bosun
SCJP for the Java� 2 Platform
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!