Results 1 to 5 of 5
Thread: [SOLVED] Rounding off numbers
- 02-05-2009, 10:38 AM #1
- 02-05-2009, 05:59 PM #2
Use the BigDecimal class and use its setScale() method. You can even choose from umpteem rounding methods.
- 02-06-2009, 10:09 AM #3
thanx for your reply. would you please gime an example coz i tried using tht method and it doesnt seem to work for me
- 02-06-2009, 12:59 PM #4
Hey,i figured out how do it.Thanx for the hint
- 02-07-2009, 01:44 AM #5
Note that BigDecimal is immutable, so you have to create a new one each time you manipulate it.
double myDouble = 1879.1106288532678d;
BigDecimal myBD = null;
myBD = new BigDecimal(myDouble);
myBD = myBD.setScale(3, BigDecimal.ROUND_HALF_UP);
myBD now contains the value rounded off to 3 decimal places.
Use the Formatter class to format the value as a String with an exponent.
- By javaMike in forum Advanced JavaReplies: 15Last Post: 03-10-2010, 01:04 AM
- By rikribbers in forum Advanced JavaReplies: 2Last Post: 10-27-2008, 04:35 PM
- By trofyscarz in forum New To JavaReplies: 2Last Post: 10-14-2008, 11:46 PM
- By yo1mcool in forum New To JavaReplies: 1Last Post: 10-07-2008, 05:02 AM
- By silvia in forum New To JavaReplies: 1Last Post: 07-20-2007, 07:25 AM