Need help rounding. =/
This is my current code.
How can I make it so the output is rounded to two decimal places?
public class TwoDecimalPlaces
public static void main (String args)
inputStr = JOptionPane.showInputDialog
("Enter the number you would like rounded to two decimal places");
x = Float.parseFloat(inputStr);
outputStr = "Rounded to two Decimal Places: " + x + "\n";
"Rounding Numbers:", OptionPane.INFORMATION_MESSAGE);
I tried google searching with no luck... and I am still kind of new so the API is rather confusing to me still, lol.
Thanks for any help!
You don't want to round the number, you want to format the String that displays the number. Look at using either DecimalFormat, a subclass of NumberFormat or String.format(...).