I have an array of floats where data are stored with varying decimal points so some are 123.40000, 123.45000, 123.45600…now if i want to print these values in the string without the 0s in the end in printf() so that they are 123.4, 123.45, 123.456, without those 0s in the end. Is this possible? If so, how?
I have an array of floats where data are stored with varying decimal points
Share
Use the %g formatter:
prints
123.4
Trailing zeros are removed, but unfortunately so is the trailing decimal point if the fractional part is zero. I don’t know if there is actually any way of doing what you want directly using printf() – I think something like this is probably your best bet: