This topic is now archived and is closed to further replies.


[java] working with floats

Recommended Posts

You have to use the DecimalFormat.
Here is an example

import java.text.DecimalFormat; // Import DecimalFormat

public 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


Hope this helps

[edited by - Loves_Java on May 1, 2002 6:17:54 PM]

Share this post

Link to post
Share on other sites