aspose file tools*
The moose likes I/O and Streams and the fly likes Data outputting to excel causes numbers to change Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Data outputting to excel causes numbers to change" Watch "Data outputting to excel causes numbers to change" New topic
Author

Data outputting to excel causes numbers to change

John Graham
Greenhorn

Joined: Feb 18, 2014
Posts: 3
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?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: Feb 18, 2014
Posts: 3
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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Sorry, am I missing a factor of 10 or something? To me 8.09223E-4 looks the same as 0.000809223.
John Graham
Greenhorn

Joined: Feb 18, 2014
Posts: 3
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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Data outputting to excel causes numbers to change