• 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

XStream and scientific notation issue

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an object that I convert to XML using XStream. Occasionally I am encountering errors (not all the time) on fields that are both of type Integer and double. I get the java error java.lang.NumberFormatException: For input string: ".12625E312625" because XStream seems to be converting this number to scientific notation. I cannot figure out how this is occurring and how I should correct it. I could see if the double numbers were very large but my numbers never exceed 100,000.00 and I don't understand why it would be doing it on the Integer field. Any help would be greatly appreciated.

Thanks.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
E312625??? That has 312626 digits in. No wonder you are getting a number format exception. Only BigDecimal could handle such numbers. There must have been some error in transcription from excel.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, maybe only 312625 digits.
 
Greg Abel
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Should i change my field type?
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is your field type? The String you quoted is a number beyond the range of most number implementations. How does it get so large?
 
Greg Abel
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just have double values that don't get larger than 100,000.00. It seems that xstream is manipulating this for some reason and converting to scientific notation.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That isn't scientific notation for 100,000.00. That is scientific notation for several dozen pages of digits.
 
Greg Abel
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible that my double value has a ton of extra decimal digits? If that's the case, do I just prevent that to go to only 2 decimal places?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's definitely something suspicious about that. The largest value you can store in a java Double is somewhere around 10^307, if I have that right. Not too far from that anyway. But you're getting a number around 10^312625 in scientific notation there. That's a long way out of the Double range, and it's an understatement to say that.

It's also kind of suspicious that the string "12625" occurs both before and after the "E".

And you said the error occurs sporadically -- that could mean you have threading issues. Java formatting objects are notorious for not being thread-safe, so perhaps you're using more than one thread to do this XML serialization?
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote: . . . The largest value you can store in a java Double is somewhere around 10^307, if I have that right. . . . .

Yes, you have that right. It's 1.7976931348623157E308
 
Hey cool! They got a blimp! But I have a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic