| Author |
Rounding problem
|
Vamsi Chada
Greenhorn
Joined: Aug 12, 2004
Posts: 10
|
|
|
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
|
 |
Manuel Moons
Ranch Hand
Joined: Mar 05, 2002
Posts: 229
|
|
|
What is the format that you are using?
|
 |
Manuel Moons
Ranch Hand
Joined: Mar 05, 2002
Posts: 229
|
|
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
Joined: Mar 05, 2002
Posts: 229
|
|
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.
|
 |
Vamsi Chada
Greenhorn
Joined: Aug 12, 2004
Posts: 10
|
|
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.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
|
This thread may answer your question.
|
 |
Pat Farrell
Rancher
Joined: Aug 11, 2007
Posts: 4422
|
|
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.
|
 |
Vamsi Chada
Greenhorn
Joined: Aug 12, 2004
Posts: 10
|
|
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.
Thanks for all your answers and finally solved
|
 |
Pat Farrell
Rancher
Joined: Aug 11, 2007
Posts: 4422
|
|
Vamsi Chada wrote:I had a work around solution of multiplying my double value with 10000000 and then use the round method.
Thanks for all your answers and finally solved
I am surprised that your solution works. Its will not work in general. Be prepared to enter a QA/bug report on it when the real problem is discovered.
|
 |
 |
|
|
subject: Rounding problem
|
|
|