I gave several examples. None was intended to be dropped directly into your program, since they used different variable names and various kinds of format that might not be what you are looking for....
Type: Posts; User: Zaphod_b
I gave several examples. None was intended to be dropped directly into your program, since they used different variable names and various kinds of format that might not be what you are looking for....
DecimalFormat and (NumberFormat) are in the java.text package, so at the beginning of your program, you can put the following statement to let Java know that's what you are going to use:
import...
As documented in the links that I gave in my first post:
The static format method of the NumberFormat returns a String. The static format method of the DecimalFormat classes returns a String.
...
That code will not compile, so I can't see how it could be giving a runtime exception. For best chances of getting helpful responses with fewest iterations it is recommended to post the exact code...
Here's the thing: The author of Java made it "easy" to print out numerical values as long as you don't care what they look like. If you want to print floating point numbers formatted a certain way,...