Results 1 to 5 of 5
Thread: [SOLVED] Rounding off numbers
- 02-05-2009, 09:38 AM #1
- 02-05-2009, 04:59 PM #2
Use the BigDecimal class and use its setScale() method. You can even choose from umpteem rounding methods.
- 02-06-2009, 09: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, 11:59 AM #4
Hey,i figured out how do it.Thanx for the hint
cheerz!!
- 02-07-2009, 12: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.
Similar Threads
-
rounding double to two decimal places
By javaMike in forum Advanced JavaReplies: 15Last Post: 03-10-2010, 12:04 AM -
rounding a double in a number of significant numbers
By rikribbers in forum Advanced JavaReplies: 2Last Post: 10-27-2008, 03:35 PM -
printing two smallest numbers from a series of numbers
By trofyscarz in forum New To JavaReplies: 2Last Post: 10-14-2008, 11:46 PM -
Need help rounding. =/
By yo1mcool in forum New To JavaReplies: 1Last Post: 10-07-2008, 05:02 AM -
Help with java Rounding
By silvia in forum New To JavaReplies: 1Last Post: 07-20-2007, 07:25 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks