• Post Reply Bookmark Topic Watch Topic
  • New Topic

NumberFormat does not display negatives correctly  RSS feed

 
Jehan Jaleel
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

Thanks again for your help today. Another issue I ran into with NumberFormat was with USD negative values.



Here "principal.getAmount()" is a BigDecimal with a value of -27.36 but the String printPrinicpal is "($27.36)".

So why is it putting a parenthesis instead of a minus symbol?

Thanks again.
 
Stephan van Hulst
Saloon Keeper
Posts: 7969
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's how a negative amount is often formatted in accounting. Apparently your default locale has this property.

Instead, you could use Locale.ENGLISH and then replace the '¤' in the resulting String with '$'.
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try a Formatter or the String.format() method, which uses a Formatter indirectly. Probably better than the NumberFormat classes.
 
Jehan Jaleel
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Stephan.

I replaced the above code with the below and got just the output I wanted "-$27.36".



Thanks again.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!