Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Floating point formatting in printf()

Tags:

People also ask

How do I printf a floating point?

You can do it like this: printf("%. 6f", myFloat); 6 represents the number of digits after the decimal separator.

What do you use in printf () to display a floating point value?

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 "%.

What is %f in printf?

The f in printf stands for formatted, its used for printing with formatted output.

Can I use %d for float?

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?