Re: How to format a float number?

Discussion in 'Java' started by Ahmed Moustafa, Aug 19, 2003.

  1. Ahmed Moustafa wrote:
    > How to format a float number to 2 digits after the decimal point?
    >
    > Thanks in advance!



    I got

    <code>
    DecimalFormat format = new DecimalFormat(".00");
    </code>

    and

    <code>
    DecimalFormat format = new DecimalFormat( );
    format.setMinimumFractionDigits(2);
    format.setMaximumFractionDigits(2);
    format.setGroupingUsed(false);
    </code>

    Both give the same result. But which is better? And why?
    Ahmed Moustafa, Aug 19, 2003
    #1
    1. Advertising

  2. Ahmed Moustafa <> writes:

    > Both give the same result. But which is better? And why?


    The first one, after parsing the pattern, does what your second one
    does. So the first takes slightly longer, but is also way more
    readable.
    Tor Iver Wilhelmsen, Aug 19, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy
    Replies:
    7
    Views:
    6,255
    Roedy Green
    May 10, 2004
  2. bd
    Replies:
    0
    Views:
    624
  3. Carsten Fuchs
    Replies:
    45
    Views:
    1,540
    James Kanze
    Oct 8, 2009
  4. Oscar Lok
    Replies:
    1
    Views:
    174
    David Kastrup
    Nov 19, 2006
  5. Fei Liu
    Replies:
    21
    Views:
    2,362
    John Bokma
    Dec 16, 2006
Loading...

Share This Page