1. [ Java ] Printing a decimal values
The printf method takes a format string as the first parameter. This string is printed but the parameters that follow replace the % placeholders.
%f is used for floating point values.
| Format | Code | Meaning |
| Simple | %f | The default format |
| Fixed decimal places | %.3f |
Print three decimal places. |
| Right justified | %8.3 | Print right aligned in 8 characters. Use three decimal places. |
test text
1. [ C# ] Printing a decimal values
The Write method takes a format string as the first parameter.
This string is printed but following parameters replace the {} placeholders.
In the phrase {0:8:f3} 0 indicates the first parameter
8 is the number of spaces to use (right justified), f3 means three decimal
places.
| Format | Code | Meaning |
| Simple | {0} |
Simple conversion to string |
| Three dp | {0:f3} |
Three decimal places. |
| Right aligned | {0,8:f3} |
Print right aligned in 8 characters. Use three decimal places. |
test text