I have a currency in pennies, as an integer (ex: 1234). I need the output to be: $12.34. We are not allowed to use doubles or floats on this assignment, only Integers.
Here is what I have:
totalChange = 1234;
DecimalFormat ourFormat = new DecimalFormat("$#,###.00");
String totalString = ourFormat.format(totalChange);
System.out.println("Your change of " + totalString + " is as follows:");
I would assume that the DecimalFormat would go from right to left, assigning 34 to be after the decimal point, and the 12 should be placed before.
I’m getting an output of Your change of $1234.00 is as follows:
Format will not artificially introduce decimal places not present in the input.
You could try converting to dollars and cents first, then combining the two with ‘.’
Hint (Based on comment from @DanielFischer)
Cents can be 1 or 2 digits, but you probably want to output them always as 2 digits.