0 votes
1 view
in Python by (47.8k points)

I have a floating-point number, say 135.12345678910. I want to concatenate that value to a string but only want 135.123456789. With print, I can easily do this by doing something like:

print "%.9f" % numvar

with numvar being my original number. Is there an easy way to do this?

1 Answer

0 votes
by (107k points)

By using round method, you can convert a floating-point number to a certain precision, and then copy to string see the code below:-

>>> numvar = 135.12345678910 

>>> str(round(numvar, 9)) 


To know more about this you can have a look at the following video tutorial:-

Welcome to Intellipaat Community. Get your technical queries answered by top developers !