Hi there,
I'm having trouble with floats in Java. My program accepts a number in the form of a float. The number typically has two decimals (but not always). It seems to work fine in most cases. For example, I could put in 54.67, and that number would be passed to another function. Great. However, my problem is this:
If I put in 54.60 as the number, it gets set as a float, which automatically rounds it to 54.6, and passes that to the other function. The other function doesn't work properly when this 0 is dropped. So my question is:
When using a float, how can I prevent the trailing 0 from being dropped? How can I prevent 54.60 from being turned into 54.6?
This is how I'm accepting input:
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
float f;
System.out.println("Enter number...:");
f = Float.valueOf(br.readLine()).floatValue();
x = otherFunction(f);
This has been driving me absolutely crazy, so any help would be really appreciated.
Cheers