While I’m using %g as format specifier in printf(), sometimes it rounds up upto 2 places after decimal point, sometimes upto 3 places , someimes upto 4 places…how it does so?
Actually where we should use %g instead of %f or %e for floating point numbers?
The
%gformat specifier does its rounding just like%fwould do, but if%fwould result in4.234000, then%gwill omit the trailing zeros and print4.234.%gshould be used when it makes the most sense in your output format that some numbers are printed as12345.6, while a slightly bigger number would be printed as1.235e04.