You'll need to use string formatting for this:

'{:0.3e}'.format(2.32432432423e25)

The reason is that round is for specifying the number of the digits after the ones place, which is not really relevant when your numbers are O(25).

Answer from Paul H on Stack Overflow
🌐
Python.org
discuss.python.org › python help
How does round function handle scientific notation? - Python Help - Discussions on Python.org
December 5, 2022 - Problem is, some functions in my program (for instance, tan(pi/2)) return scientific notation. I’m going to use tan(pi/2) as my example. Without rounding, it returns 1.633123935319537e+16 (this is because pi is given as a constant, not as an irrational number).
Discussions

Formatting numbers to string with 'r'-formatting for rounded precision - Ideas - Discussions on Python.org
In high school chemistry I learned to round my results to the number of significant figures given by the precision of the inputs. I now work with chemical engineers and they also practice this way of printing the bottom line. Python number string formatting cannot do this, but other languages ... More on discuss.python.org
🌐 discuss.python.org
3
October 17, 2024
I have searched high and low for weeks and I cannot find a single solution that rounds numbers properly. This is insanity, please help.
Floating point values don’t have “trailing zeros.” You’re confusing the value with how its being printed. More on reddit.com
🌐 r/learnpython
32
3
May 19, 2022
Python can't accurately convert this scientific notation to integer
the number is "6.7675656072510696e+16" "67675656072510696" but "67675656072510693" is correct 67675656072510693 is wrong, 67675656072510696 is correct. More on reddit.com
🌐 r/learnpython
10
3
January 18, 2022
Round Numbers and keep Scientific Notation R

If you look at the documentation for round() (type '?round' into the console) you'll find the signif() function that works the same, but keeps the specified number of significant digits. That's the function you're looking for.

More on reddit.com
🌐 r/RStudio
7
3
September 18, 2019
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.format_float_scientific.html
numpy.format_float_scientific — NumPy v2.1 Manual
In that case more digits than necessary to uniquely identify the value may be printed and rounded unbiased. New in version 1.21.0. ... >>> import numpy as np >>> np.format_float_scientific(np.float32(np.pi)) '3.1415927e+00' >>> s = np.float32(1.23e24) >>> np.format_float_scientific(s, unique=False, precision=15) '1.230000071797338e+24' >>> np.format_float_scientific(s, exp_digits=4) '1.23e+0024'
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.format_float_scientific.html
numpy.format_float_scientific — NumPy v2.4 Manual
In that case more digits than necessary to uniquely identify the value may be printed and rounded unbiased. New in version 1.21.0. ... Try it in your browser! >>> import numpy as np >>> np.format_float_scientific(np.float32(np.pi)) '3.1415927e+00' >>> s = np.float32(1.23e24) >>> np.format_float_scientific(s, unique=False, precision=15) '1.230000071797338e+24' >>> np.format_float_scientific(s, exp_digits=4) '1.23e+0024'
🌐
YouTube
youtube.com › let's code physics
VPython for Beginners 8 - Scientific Notation and Rounding - YouTube
New to VPython? This video series will guide you through! Code available at: http://www.glowscript.org/#/user/wlane/folder/Let'sCodePhysics/program/Rounding/...
Published   October 2, 2017
Views   1K
🌐
Python.org
discuss.python.org › ideas
Formatting numbers to string with 'r'-formatting for rounded precision - Ideas - Discussions on Python.org
October 17, 2024 - In high school chemistry I learned to round my results to the number of significant figures given by the precision of the inputs. I now work with chemical engineers and they also practice this way of printing the bottom line. Python number string formatting cannot do this, but other languages can. d3js can format numbers rounded to significant digits. var stringfloat = d3.format(".3r"); d3.select("body").appen...
🌐
Real Python
realpython.com › python-rounding
How to Round Numbers in Python – Real Python
December 7, 2024 - The np.ceil() function rounds every value in the array to the nearest integer greater than or equal to the original value: ... Hey, that’s a new number! Negative zero! Actually, the IEEE-754 standard requires the implementation of both a positive and negative zero. What possible use is there for something like this? Wikipedia knows the answer: Informally, one may use the notation “−0” for a negative value that was rounded to zero.
🌐
w3resource
w3resource.com › numpy › input-and-output › format_float_scientific.php
NumPy Input and Output: format_float_scientific() function - w3resource
The format_float_scientific() function is used to format a floating-point scalar as a decimal string in scientific notation. Provides control over rounding, trimming and padding. Uses and assumes IEEE unbiased rounding.
Find elsewhere
🌐
Scaler
scaler.com › home › topics › python scientific notation
Python Scientific Notation - Scaler Topics
October 10, 2025 - Let's create a data frame in Python using pandas and NumPy in scientific notation format. Output : The above code creates a column containing five random numbers in scientific notation format. The code creates five random numbers as we are using np.random to generate random numbers. To remove the scientific notation from the numbers generated we can use any of the following syntaxes. df.round(n) df.apply(lambda x: ‘%.nf’ % x, axis=1) pd.set_option(‘display.float_format’, lambda x: ‘%.nf’ % x) pd.options.display.float_format= ‘{:.nf}’.format ·
🌐
Reddit
reddit.com › r/learnpython › i have searched high and low for weeks and i cannot find a single solution that rounds numbers properly. this is insanity, please help.
r/learnpython on Reddit: I have searched high and low for weeks and I cannot find a single solution that rounds numbers properly. This is insanity, please help.
May 19, 2022 -

I have a simple set of needs for a function:

  • round values to a specified number of significant figures

or

  • round values to a specified decimal place (e.g. round to nearest 0.01)

in either case it must:

  1. print the values explicitly not in scientific notation

  2. print the values with their proper number of significant digits without truncating trailing zeroes


These should be simple requirements that have been done many times before but i cannot find any solution to this issue outside of doing it manually by hand. It does not need to all be one library, i will take literally any mishmash of code that works and use the sig fig rounding and decimal place rounding separately if need be. I will list below the solutions I've come across and examples where they don't work:

round() does not work because it truncates trailing zeroes, variations using the round() function with floor,log10 and so on do not remedy this. It only rounds to decimal places, it cannot round to significant figures.

round(1234.000000,3) 
#1234.0
#not 1234.000

numpy.format_float_positional does not work because of how it handles floating point arithmetic i believe:

np.format_float_positional(0.0900,3,fractional=False,unique=False)
#'0.09'
np.format_float_positional(0.0800,3,fractional=False,unique=False)
#'0.0800'

numpy.format_float_scientific does not work because it prints as an exponent, any attempt to print it explicitly results in trailing zeroes being truncated:

np.format_float_scientific(0.9000000,3,unique=False)
#'9.000e-01'
#which is fine but cannot be converted out of exponent form in any way without significant figures being lost

decimal.Decimal() does not work because it can only handle the set precision rounding, i can't see anyway to use it to round to a set number of significant figures and it does not interplay with numpy properly:

np.format_float_positional(Decimal.from_float(0.7),4,fractional=False,unique=False)
#'0.700'
#not '0.7000'
np.format_float_positional(Decimal.from_float(0.8),4,fractional=False,unique=False)
#'0.8000'
#as you can see decimal doesn't work for significant figures because i believe numpy imports the value 
#and doesn't preserve the values in the way the Decimal library intends.   
#Decimal('0.7') has similar issues

decimal.Decimal().quantize(decimal.Decimal()) does work but only for rounding to a set decimal place, it won't work for rounding to the nearest 10 or 100 as far as i can get it to work and I cannot find a way to round to a specified number of significant figures using the decimal library.

print(str(Decimal('.900000').quantize(Decimal('0.01'))))
#0.90
print(str(Decimal('93256').quantize(Decimal('100'))))
#93256
#not 93200

ideally i was thinking of a function with the syntax:

def round_value(value,number_of_significant_figures=None,decimal_precision=None):   
#when either of the kwargs is set to a number it would round based on the number of specified significant figure or to the specified decimal place as appropriate

I have tried varying combinations of the above functions/libraries with little success, inevitably one of the three requirements is violated by some reasonable number. If someone can demonstrate/direct me to a reliable way to round values meeting the listed criteria it would be immensely appreciated because i am at my wits end.

🌐
Note.nkmk.me
note.nkmk.me › home › python
Round Numbers in Python: round(), Decimal.quantize() | note.nkmk.me
January 15, 2024 - decimal.Decimal.quantize() — ... You can specify Decimal() with a string like '0.1' or '0.01'. To round the integer part, use scientific notation like '1E1'. More details will be discussed later....
🌐
Python
docs.python.org › 3 › library › decimal.html
decimal — Decimal fixed-point and floating-point arithmetic
>>> data = list(map(Decimal, '1.34 1.87 3.45 2.35 1.00 0.03 9.25'.split())) >>> max(data) Decimal('9.25') >>> min(data) Decimal('0.03') >>> sorted(data) [Decimal('0.03'), Decimal('1.00'), Decimal('1.34'), Decimal('1.87'), Decimal('2.35'), Decimal('3.45'), Decimal('9.25')] >>> sum(data) Decimal('19.29') >>> a,b,c = data[:3] >>> str(a) '1.34' >>> float(a) 1.34 >>> round(a, 1) Decimal('1.3') >>> int(a) 1 >>> a * 5 Decimal('6.70') >>> a * b Decimal('2.5058') >>> c % a Decimal('0.77') Decimals can be formatted (with format() built-in or f-strings) in fixed-point or scientific notation, using the same formatting syntax (see Format Specification Mini-Language) as builtin float type:
🌐
Sublime Text 4 Using Bash in Sublime Text
rowannicholls.github.io › python › data › rounding_off.html
Data Handling in Python: Rounding Off
from decimal import Decimal, getcontext ... = sigfigs rounded = Decimal(x) # The precision only kicks in when an arithmetic operation is performed rounded = rounded * 1 # Remove scientific notation # (if the order of magnitude of th...
🌐
Syntx Scenarios
syntaxscenarios.com › home › python › python scientific notation: how to use, convert & remove it
Python Scientific Notation: How to Use, Convert & Remove it
2 weeks ago - Python will automatically handle the conversion, but sometimes, for better readability, you might want to format it explicitly. ... The code below converts a scientific notation into a float, decimal and integer form using type casting.
🌐
Python Pool
pythonpool.com › home › blog › python scientific notation with suppressing and conversion
Python Scientific Notation With Suppressing And Conversion - Python Pool
January 1, 2024 - To convert scientific notation into a floating-point number in python, the float number can be rounded with the format and then can be used on a string in order to return the rounded float value.
🌐
Delft Stack
delftstack.com › home › howto › python › round to significant digits python
How to Round A Number to Significant Digits in Python | Delft Stack
February 2, 2024 - In Python, the %g specifier in string formats a float rounded to a specified significant figure. If the magnitude of the final number is huge, then it shows it in scientific notation.
🌐
Real Python
realpython.com › how-to-python-f-string-format-float
How to Format Floats Within F-Strings in Python – Real Python
April 24, 2024 - If you want to round numbers to significant figures, you use the lowercase letter g in the format specifier. You can also use an uppercase G, but this automatically switches the format to scientific notation for large numbers.
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.format_float_scientific.html
numpy.format_float_scientific — NumPy v2.5.dev0 Manual
In that case more digits than necessary to uniquely identify the value may be printed and rounded unbiased. New in version 1.21.0. ... Try it in your browser! >>> import numpy as np >>> np.format_float_scientific(np.float32(np.pi)) '3.1415927e+00' >>> s = np.float32(1.23e24) >>> np.format_float_scientific(s, unique=False, precision=15) '1.230000071797338e+24' >>> np.format_float_scientific(s, exp_digits=4) '1.23e+0024'
🌐
NumPy
numpy.org › doc › 2.0 › reference › generated › numpy.format_float_scientific.html
numpy.format_float_scientific — NumPy v2.0 Manual
In that case more digits than necessary to uniquely identify the value may be printed and rounded unbiased. New in version 1.21.0. ... >>> np.format_float_scientific(np.float32(np.pi)) '3.1415927e+00' >>> s = np.float32(1.23e24) >>> np.format_float_scientific(s, unique=False, precision=15) '1.230000071797338e+24' >>> np.format_float_scientific(s, exp_digits=4) '1.23e+0024'
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.format_float_scientific.html
numpy.format_float_scientific — NumPy v2.2 Manual
In that case more digits than necessary to uniquely identify the value may be printed and rounded unbiased. New in version 1.21.0. ... >>> import numpy as np >>> np.format_float_scientific(np.float32(np.pi)) '3.1415927e+00' >>> s = np.float32(1.23e24) >>> np.format_float_scientific(s, unique=False, precision=15) '1.230000071797338e+24' >>> np.format_float_scientific(s, exp_digits=4) '1.23e+0024'