Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

double manipulation

  Asked By: Daryl    Date: Apr 12    Category: Java    Views: 743

Does any body know how to convert a double so that it will have only
two decimals? For example if I enter 40.0 I wanted it to return me
40.00; if I enter 40.3245234234 I wanted to return me 40.32. If any
one know how manipulate this, please let me know



3 Answers Found

Answer #1    Answered By: Josephine Gomez     Answered On: Apr 12

Look in the package java.text, I believe it is called
NumberFormatter. You would basically pass it the
format string of "0.00", zeros tell the formatter to
put a number in this spot unconditionally.

Answer #2    Answered By: Aadi Martin     Answered On: Apr 12

I think it was DecimalFormat..............

Answer #3    Answered By: Jawwad Akram     Answered On: Apr 12

Thanks, I was trying to recall it from memory and I
knew I probably had the name of the class wrong but
the package was right.

Didn't find what you were looking for? Find more on double manipulation Or get search suggestion and latest updates.