Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2011
    Location
    India,Tamil Nadu
    Posts
    32
    Rep Power
    0

    Default How to Format a double value to 2 decimal places

    How to round double / float value to 2 decimal points in Java

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: How to Format a double value to 2 decimal places

    Are you asking how to control what is printed? Look at the DecimalFormat class or the printf method.
    Or are you asking how to change the value of the variable?
    Multiply by 100, cast to int, convert back to double, divide by 100.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: How to Format a double value to 2 decimal places

    Subject to the limitations of floating point math: What Every Computer Scientist Should Know About Floating-Point Arithmetic


    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    Join Date
    Jul 2011
    Location
    India,Tamil Nadu
    Posts
    32
    Rep Power
    0

    Default Re: How to Format a double value to 2 decimal places

    Thank you...

Similar Threads

  1. How do you format to two decimal places with println()?
    By EscSequenceAlpha in forum New To Java
    Replies: 4
    Last Post: 04-05-2012, 08:27 PM
  2. force a double to 2 decimal places
    By sehudson in forum New To Java
    Replies: 2
    Last Post: 04-03-2011, 06:52 AM
  3. keep double accurate to two decimal places
    By africanhacker in forum New To Java
    Replies: 5
    Last Post: 03-24-2011, 06:23 PM
  4. Limiting decimal places in a double
    By darek9576 in forum New To Java
    Replies: 5
    Last Post: 03-14-2010, 01:13 AM
  5. Replies: 4
    Last Post: 03-03-2009, 12:43 PM

Posting Permissions

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