Python Forum
python decimal scale precision
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python decimal scale precision
#5
(Aug-22-2019, 08:27 AM)massimo_m Wrote: Thank you, but in these examples you convert the float in decimal, while i would to have a variable with a arbitrary precision.
my needs are similar to this:



dec_value= myvalue

dec_value.setPrecision(2)

do some stuff

print dec_value.getPrecision()
and it gives me "2"

Hi!

I'm not sure what you mean by arbitrary precision. I thought, according to your original post, that you wanted the totals (for V.A.T. needs) to be shown with 2 digits after the float point (decimal point, or virgula). This is exactly what this little program does (and it rounds the numbers to 2 significant float (decimal) places, it doesn't matter if the number is shorter or longer than that):

So if you introduce 24, the program prints 24.00 €,
if you introduce 24.3, the program prints 24.30 €,
if you introduce 24.35, the program prints 24.35 €,
if you introduce 24.375, the program prints 24.38 €.

newbieAuggie2019
newbieAuggie2019

"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs
Reply


Messages In This Thread
python decimal scale precision - by massimo_m - Aug-21-2019, 03:02 PM
RE: python decimal scale precision - by massimo_m - Aug-22-2019, 08:27 AM
RE: python decimal scale precision - by newbieAuggie2019 - Aug-22-2019, 09:37 AM
RE: python decimal scale precision - by perfringo - Aug-22-2019, 11:47 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Gmpy2 Newbie Working on Precision charlesrkiss 5 619 Jan-23-2024, 04:23 PM
Last Post: charlesrkiss
  Precision with Decimal Type charlesrkiss 9 831 Jan-18-2024, 06:30 PM
Last Post: charlesrkiss
  Python Struct Question, decimal 10, \n and \x0a. 3python 2 693 Aug-11-2023, 09:29 AM
Last Post: 3python
  How to properly scale text in postscript conversion to pdf? philipbergwerf 3 1,207 Nov-07-2022, 01:30 PM
Last Post: philipbergwerf
  Precision conversion garynewport 2 988 Oct-19-2022, 10:47 AM
Last Post: garynewport
  KeyError: 0 when trying to dedupe and match records at scale Catalytic 1 2,236 Apr-07-2022, 06:34 PM
Last Post: deanhystad
  How to use a variable in Python (2.x) to define decimal part? MDRI 4 2,373 May-07-2021, 12:39 AM
Last Post: MDRI
  Matplotlib scale julienhofmann 0 1,824 Apr-04-2021, 08:50 AM
Last Post: julienhofmann
Photo Filtering data and precision during calculations Scientifix 0 1,810 Mar-30-2021, 01:00 PM
Last Post: Scientifix
  High-Precision Board Voltage Reading from Python into PD Liam484 1 2,112 Mar-29-2021, 02:57 PM
Last Post: Marbelous

Forum Jump:

User Panel Messages

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