Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing float up to six decimal places [duplicate]

I have an issue in printing a float number. I tried:

a = 2
c = 4
print (str(c/a).format(1.6))

Output:

2.0

Required Output:

2.000000

How can I print up to 6 decimal places?

like image 357
Rohith Avatar asked Jul 01 '16 09:07

Rohith


People also ask

How do you print a float value upto 6 decimal places in Python?

Use the round() function to print a float to 6 decimal places, e.g. print(round(my_float, 6)) . The round() function will round the floating-point number to 6 decimal places and will return the result. Copied!

How do you print floating decimals?

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 "%. 3f", x would have been printed rounded to 3 decimal places.

How do I get 6 decimal places in C++?

setprecision() to Specify Decimal Points We can specify the number of decimal points to print in cout by using the setprecision() function. This function is defined in the iomanip header file, which stands for input/output manipulation.

How do you control the number of decimal places to be printed in float value?

You can do: printf("%. 2lf\n", F); printf("%. 3lf\n", F); printf("%.


1 Answers

This can be accomplished by:

print("{:.6f}".format(your value here));
like image 114
user3206656 Avatar answered Sep 26 '22 07:09

user3206656