• Post Reply Bookmark Topic Watch Topic
  • New Topic
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the format that you are using?
 
Manuel Moons
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This thread may answer your question.
 
Rancher
Posts: 4803
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4803
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.


 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic