This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Java in General and the fly likes NumberFormat Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "NumberFormat Question" Watch "NumberFormat Question" New topic
Author

NumberFormat Question

Luke Shannon
Ranch Hand

Joined: Sep 30, 2004
Posts: 239
The code below prints $100.00, I want it to print $100.00 USD. I thought from the documentation that getCurrencyInstance got me an object that could do that. The object contains the right currency...what am I doing wrong?


[ January 11, 2006: Message edited by: Luke Shannon ]

Luke
SCJP
Luke Shannon
Ranch Hand

Joined: Sep 30, 2004
Posts: 239


This works, but still confused why the format method doesn't write out the currency on its own....

Luke
Paul Clapham
Sheriff

Joined: Oct 14, 2005
Posts: 19728
    
  10

It's because a NumberFormat is for formatting numbers. It may be that the number in question is a currency amount, or it may not. So if you want the currency description as part of the output, you have to say so.
Luke Shannon
Ranch Hand

Joined: Sep 30, 2004
Posts: 239
Hello;

I thought by calling getCurrencyInstance vs getIntegerInstance I was indicating that I wished to include currency in the output...

Luke
Paul Clapham
Sheriff

Joined: Oct 14, 2005
Posts: 19728
    
  10

Okay, I wasn't paying enough attention. Yes, you did indicate you wished to include currency in the output. And it did. See the "$" at the beginning? Change from Locale.US to Locale.UK and you'll get the British pound symbol instead.
Luke Shannon
Ranch Hand

Joined: Sep 30, 2004
Posts: 239
Yep, that works as expected. What I was hoping to get though is USD appearing after the value. But it is possible that this can't be done using format alone.

Thanks,

Luke
 
Have you checked out Aspose?
 
subject: NumberFormat Question
 
jQuery in Action, 3rd edition