Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8872435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:13:19+00:00 2026-06-14T18:13:19+00:00

Using format strings in Python I can easily print a number in scientific notation,

  • 0

Using format strings in Python I can easily print a number in “scientific notation”, e.g.

>> print '%g'%1e9
1e+09

What is the simplest way to format the number in LaTeX format, i.e. 1\times10^{+09}?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:13:20+00:00Added an answer on June 14, 2026 at 6:13 pm

    The siunitx LaTeX package solves this for you by allowing you to use the python float value directly without resorting to parsing the resulting string and turning it into valid LaTeX.

    >>> print "\\num{{{0:.2g}}}".format(1e9)
    \num{1e+09}
    

    When the LaTeX document is compiled, the above code will be turned into
    enter image description here. As andybuckley points out in the comments, the plus sign might not be accepted by siunitx (I’ve not tested it), so it may be necessary to do a .repace("+", "") on the result.

    If using siunitx is somehow off the table, write a custom function like this:

    def latex_float(f):
        float_str = "{0:.2g}".format(f)
        if "e" in float_str:
            base, exponent = float_str.split("e")
            return r"{0} \times 10^{{{1}}}".format(base, int(exponent))
        else:
            return float_str
    

    Testing:

    >>> latex_float(1e9)
    '1 \\times 10^{9}'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an integer representing a price in cents. Using Python format strings, how
When using the python struct module on can specify a format string that declares
I am trying to call Python's time.strftime() function using a Unicode format string: u'%d\u200f/%m\u200f/%Y
I have strings formatted using the code below String.Format({0,-10} {1,10}, Kills:, kills); String.Format({0,-10} {1,10},
Using String.Format how can i ensure all numbers have commas after every 3 digits
how string.format() can help to avoid using + in such statement: string statement =
How can i create a boost::format type formatter object using the character-string or std::string
I am using python's log formatter to format log records and i have a
I am using python to do some text comparison. The text format is like
In python you can use a tuple in a formatted print statement and the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.