Set Precision and Clip Trailing Zeros but Never Print Exponent
I need to: Set precision so that floats are rounded to the hundredths place ( 0.111 prints as 0.11 ) Clip trailing zeros ( 1.0 prints as 1 ) Never print an exponent ( 1000.1 prints as 1000.1 ) printf( "%.2f\n", input ); // handles 1 and 3 but not 2 printf( "%.2g\n", input ); // handles 1 and 2 but not 3 cout << setprecision( 2 ) << input << endl; // handles 1 and 2 but not 3 Is there a printf or cout option that will let me handle all of these? The C11 standard says of %f and %F (7.21.6.1:8): A double argument representing a floating-point number is converted to decimal notation in the style [