File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Decimal format like 2.07619048e-05 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Decimal format like 2.07619048e-05" Watch "Decimal format like 2.07619048e-05" New topic
Author

Decimal format like 2.07619048e-05

Richard Cook
Greenhorn

Joined: Aug 18, 2010
Posts: 22
Hi All,

I wonder if you could help me, I have to output an XML file which has lots of decimal values at a certain length.

I have tried DecimalFormat, but I think I am loosing precision, i'm not sure.

The format required is: 2.07619048e-05 etc with all values the same length.

Please could somebody help as I am pulling my hair out!

Thanks in advance.


Regards




Richard
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14338
    
  22

In what kind of way is your data stored, as float or double values, or something else?

Can you tell us in more detail (with some code, if possible) what you tried with DecimalFormat and why exactly you think you are loosing precision (do you have an example which shows this)?

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Richard Cook
Greenhorn

Joined: Aug 18, 2010
Posts: 22
Hi Jasper,

Thank you for your prompt reply.

The values are coefficients calculated on the fly using doubles.

The DevimalFormat code is as follows:


And it is currently called like:


The format I am trying to match is as follows:


But I am getting the following output (ignoring indentation):


I am not completely sure if I am loosing precision, but I would prefer if the values were all in the same format as the above example.

Many thanks


Richard

Richard Cook
Greenhorn

Joined: Aug 18, 2010
Posts: 22
I was also using:


I also changed the 00 for hashes.

Regards



Richard
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Does this help ?


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Richard Cook
Greenhorn

Joined: Aug 18, 2010
Posts: 22
Hi James,

I have just tested that with various long numbers and it is spot on, thank you so much.


Regards



Richard
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Richard Cook wrote:

I have just tested that with various long numbers and it is spot on, thank you so much.


I'm sceptical of your requirement for such a rigid format inside the XML. XML holds data and should not really care about the formatting of the values it holds. Only views of the XML data should be concerned with the format of displayed numbers.
Richard Cook
Greenhorn

Joined: Aug 18, 2010
Posts: 22
Hi James,

The reason behind this is the XML is imported in a (not very well written) system, and it was falling over with length issues, hence I wanted to get it as close to the original template as possible.

Thanks again


Richard
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Decimal format like 2.07619048e-05