• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Parse method discrepancy of NumberFormat(CurrencyFormatter)

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Greenhorn
Posts: 22
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Rahul Saple
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a bunch Simone. Even I was thinking somewhat on the same lines, but nowhere close. Thanks again.
 
Simone Aiello
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are welcome
reply
    Bookmark Topic Watch Topic
  • New Topic