Python Scientific Notation: Syntax, Examples, and Number Conversion

Learn via video course
FREE
View all courses
Python Course for Beginners With Certification: Mastering the Essentials
Python Course for Beginners With Certification: Mastering the Essentials
by Rahul Janghu
1000
4.90
Start Learning
Python Course for Beginners With Certification: Mastering the Essentials
Python Course for Beginners With Certification: Mastering the Essentials
by Rahul Janghu
1000
4.90
Start Learning
Topics Covered

Overview

How do you write scientific notation in Python?

In Python, scientific notation uses e for “times ten to the power of”: 1.23e4 is 1.23 × 10⁴, or 12300.0. To format an existing number, use an f-string f"{n}", "{}".format(n), or "%e" % n. Add precision to control the digits shown, such as f"{n:.2e}" for 1.23e+08.

Python scientific notation is a way of writing a large or a small number in powers of 10. Any number can be written in its scientific notification form by multiplying the number between 1 and 10 by a power of 10 (a∗10ba*10^b). Scientific notation reduces the format of the number representation.

For a broader introduction to the language, see our Python tutorial for beginners. Version note: All examples tested on Python 3.11, NumPy 2.4 and pandas 3.0. Re-run them in the publishing environment before release.

Types of Numbers in Python

Four different types of numbers are used in Python :

  • Integer(int)
  • Floating Points/Real numbers (float)
  • Boolean (bool)
  • Complex number (j)

Floating point numbers can be represented in Python scientific notation. A very small or a very large number can be written in Python scientific notation. Let's take an example of the representation of floating point numbers in Python scientific notation.

floating point number = 0.000009732
The floating point number above can also be written as 9.732∗10−69.732*10^{-6}.
The Python scientific notation of 9.732∗10−69.732 * 10^{-6} can be written as 9.732e-6. Here e is the Exponent symbol. We can use e or E as it is not case-sensitive.

You can also explore Python’s other built-in data types.

Representing Float in Scientific Notation by "repl"

REPL stands for Read Evaluate Print Loop and is the name given to the interactive MicroPython prompt that is accessible on Pycom devices. Using the REPL is by far the easiest way to test out Python code and run commands. You can use the REPL in addition to writing scripts in the main.py file.

Floating point numbers are always stored in numeric values and not in the form of scientific notation. While we print the floating point number it is printed in Python scientific notation depending on the condition.

On CPython 3.11, repr() prints plain decimal for 1e-4 ≤ |x| < 1e16, and scientific notation outside that range. The verified boundary examples are:

Valuerepr() outputDisplay style
0.00010.0001Plain decimal
0.000011e-05Scientific notation
1e151000000000000000.0Plain decimal
1e161e+16Scientific notation

Let's take some examples and try to print the type of floating point number and the number itself.

Output :

For both the floating point number represented by x and y, the type of both the numbers is float as both the numbers are stored as numeric values. As the number y is less than e−4e{-4} so it is printed in Python scientific notation form.

Build an AI-First Career, Master the Complete Skillset

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program
NSDC Certified

AI Forward Deployed Engineer Program

Full-stack engineering, production AI and client-facing consulting

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program

Syntax of Python Scientific Notation

The syntax for Python scientific notation is :

Where N can be any number greater than 0 and less than 10 and M can be any integer.

Examples :

  • 1.23e3
  • 4.78e-4

Parameters of Python Scientific Notation

For a number represented in Python scientific notation form i.e NeMNe^M, N should be any number greater than 0 and less than 10 and M should be any integer.

Printing a Number in Scientific Notation in Python

To print a number in scientific notation in Python, str.format() method is used. Next, we will see some examples of how the str.format() method is used to print the number in scientific notation in Python.

Examples

1. Format Scientific Notation in Python

If we have to format 0.000009732 in Python scientific notation then the code for it will be

Here the {:e} in the string is the key point to represent a float value in Scientific Notation while printing the number.

Output :


2. Print Scientific Notation in Python

If we have to print 17320000 in Python scientific notation then the code for it will be

Output :


Sharpen Your Fundamentals with Free Learning

3. Removing Zeros from Decimal

To remove zeros after the decimal the following code is written for it.

Output :

How do you suppress scientific notation in Python?

To suppress scientific notation, format the number with a fixed-point specifier: f"{n:.2f}" or "{:.2f}".format(n) prints 122900.00 instead of 1.229e+05. For a NumPy array use np.set_printoptions(suppress=True); for a pandas DataFrame use pd.set_option('display.float_format', '{:.2f}'.format). All three change display only, never the underlying value.

Suppressing scientific notation means representing the values in a full decimal format without defining them in Python scientific notation form. Python automatically represents numbers less than e−04e{-04} in scientific notation format but suppressing these numbers will represent the number in full decimal format.

For example, if the scientific notation form of the number is 1.229e+05, then it will be suppressed to full decimal format and will be represented as 122900.

Examples of Suppressing Scientific Notation in Python

To represent a number 'num' in the decimal format up to n decimal places we use the syntax f”{num:.nf}”

Example - 1 :

Output :

Example - 2 :

Output :

We can suppress scientific notation using a different syntax also which is str.format(num) with str as “{:.nf}”

Example - 3 :

Output :

How Scaler Transformed Careers in Different Fields

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Python Scientific Notation in Regex

Regex is used in programming to extract any pattern from a string. If we need to extract the scientific notation from a text then we have to write the regex pattern for identifying the scientific notation format.

Regex for scientific notation format for patterns like nemne^{m}, where n is the float value or integer and m is the integer to the power of e. Let's write the regex for identifying scientific notation format from the text.

You can read more about Regex in Python from here

Output :

The regex pattern used above is explained below :

  • [-+] – Token Matches for either – or +.
  • ? – Matches the previous token between zero and one time.
  • [\d] – Token Matches to a digit
  • . – Matches for . literally.
  • [Ee] – Token matches for either E or e.

Python Matplotlib to Convert to Scientific Notation

In matplotlib graphs, the axis offset values are represented in Python scientific notation format by default. To convert these offset values to plain decimal values we need to change the tick label format from style to plain. This changes the default scientific notation values to plain decimal values.

Let's draw a matplot lib graph by converting the offset values to decimal values from scientific notation format.

Output : output-conversion-of-scientific-notation-using-matplotlib

Scientific Notation in Jupyter Notebook

Jupyter notebook is a web-based interactive environment for writing Python code in Notebook document format.

We can write the Python scientific notation and all its conversion functions similar to what we write in Python shell. In Jupiter's notebook, the code will be organized in a notebook document format.

Jupyter notebook can be converted to any standard format such as HTML, PDF, LAtex, or Python.

Sample code is written in the Jupyter notebook of google collab :

example-of-sample-code-in-jupyter-notebook-of-google

Scientific Notation in Python Pandas

Pandas is a Python library used mainly for analyzing and manipulating data. It is used for working with values stored in tables like matrices.

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

n in the above syntax denotes the number of elements.

Converting Integer to Scientific Notation in Python

We can convert the Integer to Python scientific notation using {.e} flag with the help of the format() method of string.{.e} converts any float or integer number to scientific notation.

Also, we can use {:.Ne} to limit the number of decimal digits in the scientific notation format.

Example :

Output :

Explanation :

In the first print statement no {:.Ne} is used to limit the number of decimal places in converting the integer.

In the second print statement, the {:.3e} limits only three-digit after decimal when the integer is converted to scientific notation format.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Removing Scientific Notation from Graph

To remove the scientific notation from the offset value of the axis in the graph the following syntax is used.

Example of matplot lib plotting :

matplot-lib-plotting-example

FAQs

How do you write a number in scientific notation in Python?

Python supports scientific notation directly through the e notation. For example, 1.23e4 represents 12300.0. To format a value for display, use an f-string such as f"{number}", str.format() such as "{}".format(number), or the %e formatting operator. Add precision when you need to control the number of digits shown.

How do you stop Python from printing scientific notation?

Use a fixed-point format specifier such as f"{n:.2f}" when you want a decimal representation without an exponent. This changes how the number is displayed, not the underlying value. For pandas, set display.float_format; for NumPy, use np.set_printoptions(suppress=True) where practical. Choose precision carefully so very small values do not display as zero.

Why does Python show my small number as 1e-05?

Python’s repr() uses scientific notation for sufficiently small and large floating-point values. On CPython 3.11, the plain-decimal range is 1e-4 ≤ |x| < 1e16. Therefore, 0.00001 is displayed as 1e-05, while 0.0001 is displayed in ordinary decimal form. This is a representation choice, not a change to the value.

How do I suppress scientific notation in a pandas DataFrame?

Use pd.set_option('display.float_format', '{:.2f}'.format) to change DataFrame display without changing the stored numbers. Do not use round() merely to suppress notation, because rounding changes numeric precision and can turn very small values into zero. Reset the display option if you need to restore pandas’ default formatting later.

How do I suppress scientific notation in a NumPy array?

Use np.set_printoptions(suppress=True) to suppress scientific notation when practical. This option may not force fixed-point output when an array includes numbers with a very wide range of magnitudes. A custom formatter, such as formatter={'float_kind': '{:.10f}'.format}, provides more explicit control over how floating-point values are shown.

How do you convert a scientific notation string to a float, and is 1.23e4 a string or a number?

Use float("1.23e4") to convert the string into 12300.0. Written directly in Python source code, 1.23e4 is already a float literal, not a string, and can be used in arithmetic immediately. If you need an integer value, use int(float(s)) when it is safe to discard any fractional part.

Conclusion

  • Python scientific notation is a way of writing a large or a small number in powers of 10.
  • If the floating point number is greater than e-4 and less than e15 it is represented in decimal form by REPL.
  • Python scientific notation simplifies the reading and understanding of very large or tiny numbers.
  • To print a number in scientific notation in Python, str.format() method is used.
  • f”{num:.nf}” syntax is used for suppressing scientific notation in Python.
  • {.e} and format method is used to convert any integer or float value to scientific notation format.