

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to display a float with two decimal places in Python?
You can use string formatting to format floating point numbers to a fixed width in Python.For example, if you want the decimal points to be aligned with width of 12 characters and 2 digits on the right of the decimal, you can use the following:
>>>x = 12.35874 >>>print "{:12.2f}".format(x) 12.36
You can also achieve this result using string interpolation and formatting. For example:
>>>x = 12.35874 >>>print "% 12.2f" % x 12.36
- Related Questions & Answers
- How to parse float with two decimal places in JavaScript?
- Display 3 decimal places in MySQL?
- How to display Y-axis labels with more decimal places in R?
- Trying to round a calculation to two decimal places in a new column with MySQL?
- How to find the percentage for frequencies stored in a vector with two decimal places in R?
- Format amount values for thousands number with two decimal places in MySQL?
- How to limit Decimal Places in Android EditText?
- Python program to convert float decimal to octal number
- How to round a number to n decimal places in Java
- Display the warning message when a FLOAT value is inserted into DECIMAL in MySQL?
- How to format number to 2 decimal places in MySQL?
- Java Program to Round a Number to n Decimal Places
- How to display numbers with decimal in R data frame column?
- How to truncate a numerical vector to a specified number of decimal places in R?
- How to generate random samples rounded to 4 decimal places in R?
Advertisements