What format string in printf or iomanip operator in iostream should I use to print the float in the following format:
- 125.0 => 125
- 125.1 => 125.1
- 125.12312 => 125.12
- 1.12345 => 1.12
- 1234.1235 => 1234.12
In short, print at most 2 digits after the point, but remove all trailing zeros.
I tried %.2f but doesn’t work because it prints 125.00 and 125.10 for the first 2 cases.
Looks like I figured out some simple work around:
would solve most common cases. One thing that can’t to solved is f > 10e7, which cout will print f in scientific notion.