
-----------------------------------
ScarletSkyFury
Wed Nov 07, 2007 2:14 pm

Limiting decimals on a float output
-----------------------------------
Okay so basicaly I want the result of calculation to come out with max 2 decimals

Eg. 23.55 and not 23.556849

Any ideas?

Thanks in advanced

-----------------------------------
HeavenAgain
Wed Nov 07, 2007 3:28 pm

RE:Limiting decimals on a float output
-----------------------------------
System.out.printf("%.2f",23.556849);
or look up Math.round , but printf is better

-----------------------------------
Tony
Wed Nov 07, 2007 3:59 pm

RE:Limiting decimals on a float output
-----------------------------------
well Math.round will... round. printf is used for formatting. The latter is probably a better approach in this case.

-----------------------------------
ScarletSkyFury
Wed Nov 07, 2007 7:58 pm

Re: Limiting decimals on a float output
-----------------------------------
Im using JOptionPane >