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

# Rounding problem

Greenhorn
Posts: 10
• Number of slices to send:
Optional 'thank-you' note:
Iam taking a String from a file which is actuallya number with 18 decimals long and the Decimal format is rounding that in scientific notation to 8 decimals whereas i want the number in decimal notation . Plz help me over this

Ranch Hand
Posts: 229
• Number of slices to send:
Optional 'thank-you' note:
What is the format that you are using?

Manuel Moons
Ranch Hand
Posts: 229
• Number of slices to send:
Optional 'thank-you' note:
I am not absolutely sure what you want to do but I think you are running into problems that the double can not contain the information that you wish to store in it.

Try using the BigDecimal class.

Let me know if this is what you need?

If you want to round it you can use this

[ June 22, 2005: Message edited by: Manuel Moons ]

Manuel Moons
Ranch Hand
Posts: 229
• Number of slices to send:
Optional 'thank-you' note:

Output
============
bigdecimal === 123344534456550.12333
bigdecimalafter rounding === 1.2334453445655012E14

for the follwoing values

value 0.0000000000000 the outputis 0.0
value 0.000000165 the outputis 1.6E-7
value 0.00000000 the outputis 0.0
value 0.0000056789 the outputis 6.0E-6
value 0.00000545 the outputis 5.4E-6
value 0.123333547999 the outputis 0.12333355
value 123344534456550.12333 the outputis1.2334453445655012E14

What i need the number in Decimal not in scientific notation Plz help me over this if possible .i would be grateful to you for this

regards

vamsi

Vamsi,

I think you are trying to put to large number into a double. I think with the largest values we are loosing some precision. I'm not really sure what the largest values are that a double can contain. Maybe you should pose that question!

The scientific notation issue can be resolved using the decimalformat class.

Greenhorn
Posts: 10
• Number of slices to send:
Optional 'thank-you' note:
Thanks for the help. But I still have a question here

I want to know when I insert a large decimal value , I mean with 20 places of precision into a double variable, How much precision is stored in the double variable.

Marshal
Posts: 79508
379
• Number of slices to send:
Optional 'thank-you' note:

Rancher
Posts: 4804
7
• Number of slices to send:
Optional 'thank-you' note:
Campbell gave you a link to the answer. But more fundamentally, there is no use for floating point if you need 20 digits of accuracy. Or none that mortals do, and the numerical analyst that do it for a living know lots more, and are still probably not using floats/doubles.

When you are calculating the gravitational pull of a comet on a planet, then its important, but for those calculations, you don't think about using doubles.

Greenhorn
Posts: 10
• Number of slices to send:
Optional 'thank-you' note:
I had to sum up the percentage calls per customer which was taking atleast 20 places of decimal.
Some weird requirement but the big decimal has a performance issue but I had a work around solution of multiplying my double value with 10000000 and then use the round method.

Pat Farrell
Rancher
Posts: 4804
7
• Number of slices to send:
Optional 'thank-you' note:

Vamsi Chada wrote:I had a work around solution of multiplying my double value with 10000000 and then use the round method.