Convert floating point number to a certain precision

0 votes

If i consider the following floating point number:  135.12345678910 and if i want to concatenate that value to a string, but only till 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?

Oct 18, 2018 in Python by ana1504.k
• 7,870 points

1 answer to this question.

0 votes
With Python < 3 (e.g. 2.6 [see comments] or 2.7), there are two ways to do so.

# Option one
older_method_string = "%.9f" % numvar

# Option two
newer_method_string = "{:.9f}".format(numvar)
answered Oct 18, 2018 by SDeb
• 13,180 points

Related Questions In Python

0 votes
1 answer

How to round a floating point number up to certain decimal place in Python?

This is normal (and has nothing to do ...READ MORE

answered Oct 8, 2018 in Python by charlie_brown
• 7,720 points
0 votes
1 answer

how to find factorial of a number?

You can find factorial by many ways. ...READ MORE

answered May 4, 2018 in Python by aayushi
• 750 points
0 votes
2 answers

How to calculate square root of a number in python?

calculate square root in python >>> import math ...READ MORE

answered Apr 2 in Python by anonymous
0 votes
1 answer

Convert dictionary keys to a list

list.(dictionary.keys()) READ MORE

answered Jun 28, 2018 in Python by Hamartia's Mask
• 1,580 points
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 344 views
0 votes
1 answer

How do I convert a Python program to a runnable .exe Windows program?

Understand that every 'freezing' application for Python ...READ MORE

answered Oct 12, 2018 in Python by SDeb
• 13,180 points
0 votes
1 answer

How to convert a Unicode string to string

It can be done in the following ...READ MORE

answered Oct 16, 2018 in Python by SDeb
• 13,180 points