aspose file tools*
The moose likes Java in General and the fly likes Double to string?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Double to string??" Watch "Double to string??" New topic
Author

Double to string??

Vijay Kashyap
Ranch Hand

Joined: Jul 30, 2001
Posts: 74
Hi,
It seems a trivial issue but I am not able to resolve it. I am getting a very big integer value from database which maps to float/double value in Java. As the value can exceed 24 characters hence Java long is ruled out. My problem is to display the value as it is with out any exponential and without any rounding of. As of now I am using DecimalFormat but still the values are rounded off.
Ex: My value in database is 956000000000000000000024.
What I am getting is 956000000000000000000000.
Can somebody help me out on this.
Regards,
Vijay
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
You are probably running into the precision limitations of float/double. The only faithful representation would be BigDecimal, and that is what I would suggest you use.
- Peter
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
I agree with Peter - the data you need is getting lost in during the conversion to double, before you make any attempt to print the output, no matter how you format it. However if the number is fundamentally an integer, then BigInteger is a better fit than BigDecimal. Either one will work, but BigDecimal is needlessly slow if there's never a fractional value that needs to be maintained.


"I'm not back." - Bill Harding, Twister
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Ah, yes, BigInteger of course. Thanks.
- Peter
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Double to string??