You can do it like this: printf("%. 6f", myFloat); 6 represents the number of digits after the decimal separator.
we now see that the format specifier "%. 2f" tells the printf method to print a floating point value (the double, x, in this case) with 2 decimal places. Similarly, had we used "%.
The f in printf stands for formatted, its used for printing with formatted output.
no %d is decimal integer. use %f or %lf. you cannot send a float to printf().
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With