You could use %g to achieve this:

'%g'%(3.140)

or, with Python ≥ 2.6:

'{0:g}'.format(3.140)

or, with Python ≥ 3.6:

f'{3.140:g}'

From the docs for format: g causes (among other things)

insignificant trailing zeros [to be] removed from the significand, and the decimal point is also removed if there are no remaining digits following it.

Answer from unutbu on Stack Overflow
🌐
w3resource
w3resource.com › python-exercises › string › python-data-type-string-exercise-32.php
Python: Print the following floating numbers with no decimal places - w3resource
June 12, 2025 - Write a Python program to print the following positive and negative numbers with no decimal places. ... # Define a variable 'x' and assign it the value 3.1415926 (a positive floating-point number). x = 3.1415926 # Define a variable 'y' and assign it the value -12.9999 (a negative floating-point number). y = -12.9999 # Print an empty line for spacing. print() # Print the original value of 'x' with a label. print("Original Number: ", x) # Format the value of 'x' with no decimal places and print it.
Discussions

python - dropping trailing '.0' from floats - Stack Overflow
I'm looking for a way to convert numbers to string format, dropping any redundant '.0' The input data is a mix of floats and strings. Desired output: 0 --> '0' 0.0 --> '0' 0.1 --> '0.1' 1.... More on stackoverflow.com
🌐 stackoverflow.com
keep trailing 0's in floats?
The Decimal library is great for this. This helps you avoid floating point arithmetic errors too. More on reddit.com
🌐 r/learnpython
6
2
July 20, 2017
python - How to format a float with a maximum number of decimal places and without extra zero padding? - Stack Overflow
I need to do some decimal place formatting in python. Preferably, the floating point value should always show at least a starting 0 and one decimal place. Example: Input: 0 Output: 0.0 Values with... More on stackoverflow.com
🌐 stackoverflow.com
python - How to print float to n decimal places including trailing 0s? - Stack Overflow
I need to print or convert a float number to 15 decimal place string even if the result has many trailing 0s eg: ... I also saw various people online who put the float into a string and then added trailing 0's manually but that seems bad... ... Side note, but that last 2 is not a rounding error exactly. The number 6.2, like many other real numbers, is not exactly representable with a floating point variable in a computer. See docs.python... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Python.org
discuss.python.org › python help
General way to print floats without the .0 part - Python Help - Discussions on Python.org
May 19, 2024 - I’m building SVG code using data interpolation (f-strings and .format), and I have elements (the size of the graph for one) that are internally floats but which are usually integers. But when printing floats, the .0 part is always included. Is there a standard str-interpolation idiom that turns 24.125 into “24.125” but 25.0 into “25” ?
🌐
Python
docs.python.org › 3 › library › decimal.html
decimal — Decimal fixed-point and floating-point arithmetic
In decimal floating point, 0.1 + 0.1 + 0.1 - 0.3 is exactly equal to zero. In binary floating point, the result is 5.5511151231257827e-017. While near to zero, the differences prevent reliable equality testing and differences can accumulate.
🌐
Python documentation
docs.python.org › 3 › tutorial › floatingpoint.html
15. Floating-Point Arithmetic: Issues and Limitations — Python 3.14.7 documentation
Since all of these decimal values share the same approximation, any one of them could be displayed while still preserving the invariant eval(repr(x)) == x. Historically, the Python prompt and built-in repr() function would choose the one with 17 significant digits, 0.10000000000000001. Starting with Python 3.1, Python (on most systems) is now able to choose the shortest of these and simply display 0.1. Note that this is in the very nature of binary floating point: this is not a bug in Python, and it is not a bug in your code either.
🌐
Finxter
blog.finxter.com › home › learn python blog › python print float without decimal points
Python Print Float Without Decimal Points - Be on the Right Side of Change
August 26, 2021 - How to print the number without decimal remainder? x = 123.456 print(x) # Desired output: 123 # Real output: 123.456 · Python’s built-in function int(x) converts any float number x to an integer by truncating it towards 0.
🌐
AskPython
askpython.com › python › examples › formatting-floats-without-trailing-zeros
How to Format Floats Without Trailing Zeros? - AskPython
May 12, 2023 - Python offers four effective methods to remove trailing zeros from float values: the to_integral() and normalize() functions, the str() and rstrip() functions, a while loop, and the float() function.
Find elsewhere
🌐
Linux find Examples
queirozf.com › entries › python-number-formatting-examples
Python number formatting examples
August 2, 2023 - Truncate float at 2 decimal places · Left padding with zeros · Right padding with zeros · Use commas as thousands separator · Interpolate variable with f-strings · ValueError: zero length field name in format · All examples assume Python 3+ See the difference between truncating and rounding a number · All examples can be viewed on this jupyter notebook · In other words, round it up to the nearest integer and format: print('{:.0f}'.format(8.0)) # >>> '8' print('{:.0f}'.format(8.9)) # >>> '9' print('{:.2f}'.format(5.39120)) # >>> '5.39' Format a number as a percentage, with 2 decimal places ·
🌐
Luc
anh.cs.luc.edu › python › hands-on › 3.1 › handsonHtml › float.html
1.14. Decimals, Floats, and Floating Point Arithmetic — Hands-on Python Tutorial for Python 3
Read the following example interpreter sequence showing possibilities when a float is being formatted: >>> x = 23.457413902458498 >>> s = format(x, '.5f') >>> s '23.45741' >>> format(x, '.2f') '23.46' >>> x 23.457413902458498 · Note that the results are rounded not truncated: the result to two places is 23.46, not 23.45. The formatting string '.5f' means round to 5 places after the decimal point.
🌐
The Web Dev
thewebdev.info › home › how to format floats without trailing zeros with python?
How to format floats without trailing zeros with Python? - The Web Dev
October 23, 2021 - We interpolate x into a string and then call rstrip with 0 and '.' to remove trailing zeroes from the number strings. Therefore, n is 3.14. To format floats without trailing zeros with Python, we can use the rstrip method. ... Sometimes, we want to format a string in Python. In this article, we'll look at… ... Sometimes, we want to parse data in JSON format with Python. In this article, we'll… · How to limit floats to two decimal points with Python?
🌐
Medium
medium.com › @coucoucamille › float-formatting-in-python-ccb023b86417
Simple Float Formatting in Python | by Coucou Camille | Medium
June 15, 2022 - Syntax: "{:.2f}%".format(num) or "{:.2%}".format(num) to format num as a percentage with 2 decimal places. ... It adds trailing zeros to the end if the specified decimal number exceeds the original decimal place of the number:
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › functions › format.html
format — Python Reference (The Right Way) 0.1 documentation
The precision is a decimal number indicating how many digits should be displayed after the decimal point for a floating point value formatted with ‘f’ and ‘F’, or before and after the decimal point for a floating point value formatted with ‘g’ or ‘G’. For non-number types the field indicates the maximum field size - in other words, how many characters will be used from the field content.
🌐
freeCodeCamp
freecodecamp.org › news › 2f-in-python-what-does-it-mean
%.2f in Python – What does it Mean?
June 22, 2022 - The %f formatter is specifically used for formatting float values (numbers with decimals). We can use the %f formatter to specify the number of decimal numbers to be returned when a fl...
🌐
GeeksforGeeks
geeksforgeeks.org › python › precision-handling-python
Precision Handling in Python - GeeksforGeeks
December 19, 2025 - Given a number, the task is to control its precision either by rounding it or formatting it to a specific number of decimal places. For Example: Input: x = 2.4 Output: Integral value = 2 Smallest integer greater than x = 3 Greatest integer smaller than x = 2 · Let's explore different ways to do this task in Python. This method lets you reduce a floating-point number to a chosen number of decimal places.