my dog learned polymorphism*
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 Murach's Java Servlets and JSP this week in the Servlets 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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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
 
Don't get me started about those stupid light bulbs.
 
subject: NumberFormat Question
 
Similar Threads
double
printout "�" turns to u`
Help with currency symbol
testing a private method with JUnit / Coverlipse
NumberFormat parsing currency value failure