This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes NumberFormat parsing currency value failure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "NumberFormat parsing currency value failure" Watch "NumberFormat parsing currency value failure" New topic

NumberFormat parsing currency value failure

O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430

Why is the following generating parse exceptions when parsing using the Currency instances of Number format.

The output of the above is

It looks like parsing of numbers is fine but it is choking when it comes to use the two currency instances namely:

Also is there a way i can find out what is the type of the object being processed inside the for loop? I used "nf.getClass().getName()" in the above example but it always returns the generic type "DecimalFormat". I want to be able to know if it is processing a currency instance or a number instance.

Thanks in advance.
John Stark
Ranch Hand

Joined: Jul 19, 2011
Posts: 185
I guess you need the currency symbol:

I am not sure but I think new Locale("fr") will not work as this is a language and not a region. There are many regions outside France where French is spoken. Therefore you need a region like new Locale("en","us"));.

O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430

Thanks John.
I agree. Here's the link:
subject: NumberFormat parsing currency value failure
It's not a secret anymore!