Results 1 to 5 of 5
  1. #1
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    7

    Post [SOLVED] Rounding off numbers

    Hi pple,
    How can i make 1879.1106288532678 to appear as 1.879E3??
    Your response will be highly appreciated

  2. #2
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    Use the BigDecimal class and use its setScale() method. You can even choose from umpteem rounding methods.

  3. #3
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    7

    Default

    thanx for your reply. would you please gime an example coz i tried using tht method and it doesnt seem to work for me

  4. #4
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    7

    Default

    Hey,i figured out how do it.Thanx for the hint
    cheerz!!

  5. #5
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    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

  1. rounding double to two decimal places
    By javaMike in forum Advanced Java
    Replies: 15
    Last Post: 03-10-2010, 01:04 AM
  2. rounding a double in a number of significant numbers
    By rikribbers in forum Advanced Java
    Replies: 2
    Last Post: 10-27-2008, 04:35 PM
  3. printing two smallest numbers from a series of numbers
    By trofyscarz in forum New To Java
    Replies: 2
    Last Post: 10-15-2008, 12:46 AM
  4. Need help rounding. =/
    By yo1mcool in forum New To Java
    Replies: 1
    Last Post: 10-07-2008, 06:02 AM
  5. Help with java Rounding
    By silvia in forum New To Java
    Replies: 1
    Last Post: 07-20-2007, 08:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •