[java] working with floats
Does anyone know how do you cut the float point decimal places to the hundreth place? how do I get 1.23999999999 to be
1.24?
You have to use the DecimalFormat.
Here is an example
Hope this helps
[edited by - Loves_Java on May 1, 2002 6:17:54 PM]
Here is an example
import java.text.DecimalFormat; // Import DecimalFormatpublic class it{ public static void main(String args[]) { // Used to set the decimalFormat to two decimal places DecimalFormat twoDigits = new DecimalFormat ("0.00"); float num = 1.23999999999999; // Print out the number and force it to two decimal places System.out.println(twoDigits.format(num)); }}
Hope this helps
[edited by - Loves_Java on May 1, 2002 6:17:54 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement