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

BigDecimal is driving me crazy

Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

i wrote a class to compute e


this works fine but only to a certain precision. so i am trying to use BigDecimal. at first i was getting an exception when i divided but i learned i had to specify the rounding. i did that but now i get 2 as an answer


SCJP
Visit my download page
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

The first thing that I thought when I read that code was "How does BigDecimal.divide know how many decimal places to use?"
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

yeah i think that might be the problem. i guess i was assuming a large default value for that. this is the first time i have tried using this class.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

Off topic, but I have two small improvements for you:

Use BigDecimal.ONE and BigDecimal.valueOf(j). The former will definitely reuse an existing object, the latter will probably do so as well. Currently, all values from 0 to 10 are cached; that already saves you up to 10 extra objects per loop.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: BigDecimal is driving me crazy