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

  • SEARCH
  • Home
  • 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 8684755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:23:10+00:00 2026-06-12T22:23:10+00:00

Note: I’m already using decimal.Decimal What is the best way to perform and display

  • 0

Note: I’m already using decimal.Decimal

What is the best way to perform and display calculations to the end user when you are required to output in the following rough style:

Item - £ 70.10 
Item - £  5.67
Item - £ 10.33

--------------
Total  £ 86.10

I was always taught in maths as a kid to not round before your final answer, else you’ll lose precision, but in this case if you don’t it looks like we have calculation errors. as the calculation behind the display is not the same as the user would do from the numbers displayed to them.

EG:

My app will be doing: 70.1034 + 5.6693 + 10.333333333 = 86.1060333 (86.11 2dp)

My end user will be doing as above: 70.10 + 5.67 + 10.33 = 86.10

Therefore i appear to be incorrect. What is the best way to overcome this? (I mean generally, but python specific methods will help too)

  • 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-12T22:23:12+00:00Added an answer on June 12, 2026 at 10:23 pm

    Use the decimal module to get math that works out correctly. You can set it so each value will automatically use two decimal places.

    >>> decimal.getcontext().prec = 2
    >>> decimal.Decimal(1)/decimal.Decimal(3)
    Decimal('0.33')
    

    When you’re working with money, it’s normal to lose precision at each intermediate calculation.

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

Sidebar

Related Questions

(Note: This is not a question about what is the best way with code
Note: I had another similar question about how to GZIP data using Ruby's zlib
NOTE: I am a new user so I'm not allowed to post images nor
NOTE: The scenario is using 2 entity framework models to sync data between 2
Note: Already asked in this post (asked on StackOverflow) . However, the problem is
Note: A closure cannot call any user-defined function, because the function's context is not
NOTE: Please, don't code it for me. I already have a home-rolled function to
Note: My question is not why the queries are failing. Using WampServer and phpMyAdmin.
Note: new to mysql I am trying to get points from user id (
NOTE: XMLIgnore is NOT the answer! OK, so following on from my question on

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.