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 626593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:26:09+00:00 2026-05-13T19:26:09+00:00

I want to display in a HTML page some datas with errors, for example:

  • 0

I want to display in a HTML page some datas with errors, for example:

(value, error) -> string
(123, 12) -> (12 +- 1) x 10^1
(4234.3, 2) -> (4234 +- 2)
(0.02312, 0.003) -> (23 +- 3) x 10^-3

I’ve produced this:


from math import log10
def format_value_error(value,error):
    E = int(log10(abs(error)))
    val = float(value) / 10**E
    err = float(error) / 10**E
    return "(%f +- %f) x 10^%d" % (val, err, E)

but I’ve some difficulties with rounding. Are there some libraries with this functionality?

  • 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-05-13T19:26:09+00:00Added an answer on May 13, 2026 at 7:26 pm

    I’m not sure exactly what you want, but I assume you just want to round the numbers you have to the nearest integer? If so, you can use the built-in function round:

    >>> int(round(1.5))
    2
    

    Here’s the help:

    >>> help(round)
    Help on built-in function round in module __builtin__:
    
    round(...)
        round(number[, ndigits]) -> floating point number
    
        Round a number to a given precision in decimal digits (default 0 digits).
        This always returns a floating point number.  Precision may be negative.
    

    If you want to round down you can use floor from math. I think you actually want to use this after taking the logarithm, rather than just casting to int, as int(-0.5) is 0, not -1 as you want. Here’s a modified version of your program that I think does what you want:

    from math import log10, floor
    def format_value_error(value,error):
        E = int(floor(log10(error)))
        val = int(round(float(value) / 10**E))
        err = int(round(float(error) / 10**E))
        return "(%d +- %d) x 10^%d" % (val, err, E)
    
    print format_value_error(123, 12)
    print format_value_error(4234.3, 2)
    print format_value_error(0.02312, 0.003)
    

    This gives the following output:

    (12 +- 1) x 10^1
    (4234 +- 2) x 10^0
    (23 +- 3) x 10^-3
    

    This is very close to what you want. The only difference is that the text x 10^0 should not be printed, but I’m sure you can find a solution for this. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 396k
  • Answers 396k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It looks like you need a Twitter API username/password to… May 15, 2026 at 3:04 am
  • Editorial Team
    Editorial Team added an answer What you want is GROUP BY (and the CASE statement):… May 15, 2026 at 3:04 am
  • Editorial Team
    Editorial Team added an answer $rowCount = 0; $colorOne = '#ffffff'; $colorTwo = '#f3f3f3'; while($row… May 15, 2026 at 3:04 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.