Python Forum
Decimal (Global precision setting)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Decimal (Global precision setting)
#1
Hello!
I am doing my first steps in programming. I am using Python 3.7.2
I opened interesting numbers for me - Decimal fixed point.
But I have problems with precision setting. Undecided
I am trying to use decimal.getcontext( ).prec function.
This example from book works great:
[Image: 9987e46cb93e.jpg]
Result:
[Image: e1e3d8841472.jpg]
But than I am trying to do my own example - the precision is not working.
[Image: bb1e24b18c08.jpg]
[Image: 4c10f6b2117d.jpg]
I want to receive 4 digits after point, but instead I received "long number". I thougt may be these number after "0", but format is correct (not ā€œ%eā€ % num).

Local precision setting also not working.

Example from book:
[Image: c3f6fb00ec54.jpg]
[Image: 0983242d3d85.jpg]

My example:
[Image: be7f74cabfc3.jpg]
[Image: 817360b3e9ee.jpg]

Thank you very much for support!
Best regards, Valentina.
Reply
#2
From documentation:

Quote:The significance of a new Decimal is determined solely by the number of digits input. Context precision and rounding only come into play during arithmetic operations.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
Use code tag @Valentina and not images.
Reply
#4
(Aug-22-2019, 12:40 PM)perfringo Wrote: From documentation:
Quote: The significance of a new Decimal is determined solely by the number of digits input. Context precision and rounding only come into play during arithmetic operations.
Thank you very much. I understood. Now it is working.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Gmpy2 Newbie Working on Precision charlesrkiss 5 550 Jan-23-2024, 04:23 PM
Last Post: charlesrkiss
  Precision with Decimal Type charlesrkiss 9 730 Jan-18-2024, 06:30 PM
Last Post: charlesrkiss
  Precision conversion garynewport 2 937 Oct-19-2022, 10:47 AM
Last Post: garynewport
Photo Filtering data and precision during calculations Scientifix 0 1,784 Mar-30-2021, 01:00 PM
Last Post: Scientifix
  High-Precision Board Voltage Reading from Python into PD Liam484 1 2,079 Mar-29-2021, 02:57 PM
Last Post: Marbelous
  python decimal scale precision massimo_m 5 5,412 Aug-22-2019, 11:47 AM
Last Post: perfringo
  Global variable does not seem to be global. Columbo 6 3,686 Jul-15-2019, 11:00 PM
Last Post: Columbo
  testing for Decimal w/o importing decimal every time Skaperen 7 4,442 May-06-2019, 10:23 PM
Last Post: Skaperen
  Trouble with decimal precision Cassie 4 3,124 Feb-14-2019, 08:23 PM
Last Post: Cassie
  precision error chris64 1 2,236 Nov-29-2017, 09:40 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

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