Results 1 to 2 of 2
- 05-19-2012, 09:16 AM #1
Member
- Join Date
- Feb 2012
- Posts
- 17
- Rep Power
- 0
The precision and scale with the divide operation on a bigdecimal
Hi
I don't understand the scale with de BigDecimal.divide(), example below. Only if I give scale zero it returns 0.25.
But I should give the precision of this method. Is the precision the same as the scale? How do I use the scale correctly?
Thanks !Java Code:public double getFraction(){ BigDecimal value1 = new BigDecimal("5000"); BigDecimal value2 = new BigDecimal("20000"); return value1.divide(value2,0).doubleValue(); }
- 05-19-2012, 09:39 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Re: The precision and scale with the divide operation on a bigdecimal
Normally you shouldn't set the scale value; a BigDecimal is a BigInteger multiplied by pow(10, -scale); the divide( ... ) method you're using sets the rounding mode for the division operator, not its scale (read teh API documentation for the BigDecimal class for details).
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Divide and Conquer
By whateverme in forum New To JavaReplies: 1Last Post: 05-20-2011, 01:51 PM -
Divide Class Into 2 or more Classes
By ŖàΫ ỏƒ Ңόρę in forum New To JavaReplies: 4Last Post: 03-29-2011, 12:19 AM -
Divide bigdecimal again
By ellhar in forum New To JavaReplies: 3Last Post: 03-23-2011, 10:19 AM -
All possible way to divide a number?
By bobocheez in forum New To JavaReplies: 4Last Post: 09-24-2010, 02:24 AM -
How to divide code in classes?
By hendrix79 in forum New To JavaReplies: 2Last Post: 12-10-2008, 05:36 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks