← Back to Miscellaneous
Question 161
DecimalFormat Optional Decimals
DecimalFormat Optional Decimals
Use DecimalFormat with the pattern '0.##' to format a decimal, removing unnecessary trailing zeros. Expected Output: Value: 12.5 In DecimalFormat patterns, '#' shows a digit only when non-zero, so trailing zeros are dropped. '0.##' allows up to 2 decimal places but hides trailing zeros (12.500 becomes '12.5'). ⚠️ AUTO-INPUT MODE: The input stream will automatically contain '12.500\n'. Use Scanner's nextDouble() to read it.
Expected Output:
Value: 12.5
Topics:
Miscellaneous
Code Editor
1
Tab to indent · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (sysout, psvm, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.