Python Forum
Force calculation result as decimal
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Force calculation result as decimal
#4
To avoid errors of floating point object representation in memory, it is better to pass strings to Decimal class, e.g.
python -c "from decimal import Decimal; print(Decimal('0.0000006') + Decimal('0.0000008'))". This likely should work in python2.6.
@vercetty92, why did you are still using Python 2.6? Constructor of Decimal class in current versions of Python, e.g. Python 3.7, could process floats directly (without errors as in your example).
Reply


Messages In This Thread
Force calculation result as decimal - by vercetty92 - Mar-19-2019, 05:15 PM
RE: Force calculation result as decimal - by nilamo - Mar-19-2019, 06:29 PM
RE: Force calculation result as decimal - by scidam - Mar-20-2019, 11:58 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  force a program to exit ? Armandito 3 2,629 May-12-2022, 04:03 PM
Last Post: Gribouillis
  best way to force an exception Skaperen 2 2,110 Oct-21-2020, 05:59 AM
Last Post: Gribouillis
  testing for Decimal w/o importing decimal every time Skaperen 7 4,536 May-06-2019, 10:23 PM
Last Post: Skaperen
  Password Brute Force 2skywalkers 9 5,493 Oct-18-2018, 02:35 PM
Last Post: buran
  Brute Force Password Guesser 2skywalkers 1 3,238 Oct-05-2018, 08:04 PM
Last Post: ichabod801
  Brute Force Pad Lock Guesser RedSkeleton007 4 4,026 Mar-03-2018, 07:42 AM
Last Post: RedSkeleton007
  brute force password from list petru 10 12,161 Apr-04-2017, 02:08 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020