• 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

Data outputting to excel causes numbers to change

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, i'm writing a program that calculates moments from a shape and writes the results to an excel spreadsheet, using the apache poi package

Anyway, i'm getting the correct figures its just when i write them to the spreadsheet, the figures mysteriously change, for example the program will produce a result like 8.092238721555691E-4, but in the spreadsheet its stored as 0.000809224....

To deepen the mystery some the figures are being stored correctly...

Has anyone any experience of something similar, or any suggestions?
 
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
Those two things look like the same number, just represented in different ways. Doesn't look incorrect to me. But remembering that you can ask Excel and Java to format numbers in a variety of ways, what specific differences can you point out?

And, welcome to the Ranch!
 
John Graham
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Paul!

Yeah its seems to be the same number just with the decimal point in the wrong place.

Its only really the longer numbers that are affected, could this just be the way in which the cells of the excel document are formatted?
 
Paul Clapham
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
Sorry, am I missing a factor of 10 or something? To me 8.09223E-4 looks the same as 0.000809223.
 
John Graham
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Indeed they are the same, the first is scientific notation for the second, the issue is that my program treats the 2 numbers as 2 completely different numbers, which causes problems when it comes to comparing the numbers.

Is there anyway to stop excel from changing the numbers?
 
Paul Clapham
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
What do you mean by Excel "changing" the numbers? And this program of yours which treats the two numbers as different, is it a Java program or an Excel macro or what?
 
I'm thinking about a new battle cry. Maybe "Not in the face! Not in the face!" Any thoughts tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic