aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Parse method discrepancy of NumberFormat(CurrencyFormatter) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Parse method discrepancy of NumberFormat(CurrencyFormatter) " Watch "Parse method discrepancy of NumberFormat(CurrencyFormatter) " New topic
Author

Parse method discrepancy of NumberFormat(CurrencyFormatter)

Rahul Saple
Ranch Hand

Joined: Aug 02, 2006
Posts: 46
Below is the problematic code

The parse method of the NumberFormat(currency formatter) takes a string and returns a Number object.
However according to the book(Khalid Mughal), the space character which is used as a grouping character in formatting numbers in the norwegian locale, acts as a delimiter in a string and thereby results in the termination of any parsing.
If so, why does the second parse call return the original Number object while the first fails, when both accept the same string value as an argument.
Does it have to do anything with how the String is represented internally by the JVM?
Simone Aiello
Greenhorn

Joined: Oct 13, 2010
Posts: 22
Effectively the input string "kr 1 233 232,00" and the one printed by the console, originated by the parsing, are different...
The space used as separator is a non-breaking space (ASCII code 160), while the other is breaking ( ASCII code 32)

you can perform a test by yourself, applying this on the two strings


The important is not what you know, but when you know it...
Rahul Saple
Ranch Hand

Joined: Aug 02, 2006
Posts: 46
Thanks a bunch Simone. Even I was thinking somewhat on the same lines, but nowhere close. Thanks again.
Simone Aiello
Greenhorn

Joined: Oct 13, 2010
Posts: 22
You are welcome
 
Don't get me started about those stupid light bulbs.
 
subject: Parse method discrepancy of NumberFormat(CurrencyFormatter)