Я хочу распечатать в двойном порядке, как следующие правила:
1) No scietific notation
2) Maximum decimal point is 3
3) No trailing 0.
Например:
0.01 formated to "0.01"
2.123411 formatted to "2.123"
2.11 formatted to "2.11"
2.1 formatted to "2.1"
0 formatted to "0"
Используя .precision (3) и std :: fixed, я могу выполнить только правило 1) и правило 2), но не правило 3)
0.01 formated to "0.010"
2.123411 formatted to "2.123"
2.11 formatted to "2.110"
2.1 formatted to "2.100"
0 formatted to "0"
Пример кода приведен ниже:
#include <iostream>
int main() {
std::cout.precision(3);
std::cout << std::fixed << 0.01 << std::endl;
std::cout << std::fixed << 2.123411 << std::endl;
std::cout << std::fixed << 2.11 << std::endl;
std::cout << std::fixed << 2.1 << std::endl;
std::cout << std::fixed << 0 << std::endl;
getchar();
}
есть идеи?