• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Double to string??

 
Vijay Kashyap
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, yes, BigInteger of course. Thanks.
- Peter
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic