Python Forum
python decimal scale precision
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python decimal scale precision
#2
Hi!

I think you could use something like this:

print("\nBuongiorno.")
totale = input("Per favore, inserisci l'importo totale da pagare.\n\n")
decimali = float(totale)
print("\nL'importo totale è di %.2f"% round(decimali,2), "€. Grazie per fare affari con noi.")
And here I give you some inputs and outputs from running this little program:

Buongiorno. 
Per favore, inserisci l'importo totale da pagare.

24

L'importo totale è di 24.00 €. Grazie per fare affari con noi.
Buongiorno. 
Per favore, inserisci l'importo totale da pagare.

24.3

L'importo totale è di 24.30 €. Grazie per fare affari con noi.
Buongiorno. 
Per favore, inserisci l'importo totale da pagare.

24.35

L'importo totale è di 24.35 €. Grazie per fare affari con noi.
Buongiorno. 
Per favore, inserisci l'importo totale da pagare.

24.375

L'importo totale è di 24.38 €. Grazie per fare affari con noi.
Please, keep in mind that as it is, this program gives you the total amount with a 'dot' (.) to separate the integer digits from the decimal digits, and not the Italian 'virgola' (,), which would require much more twisting to the code.

I hope this could help you,

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 newbieAuggie2019 - Aug-21-2019, 10:08 PM
RE: python decimal scale precision - by massimo_m - Aug-22-2019, 08:27 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 689 Jan-23-2024, 04:23 PM
Last Post: charlesrkiss
  Precision with Decimal Type charlesrkiss 9 927 Jan-18-2024, 06:30 PM
Last Post: charlesrkiss
  Python Struct Question, decimal 10, \n and \x0a. 3python 2 730 Aug-11-2023, 09:29 AM
Last Post: 3python
  How to properly scale text in postscript conversion to pdf? philipbergwerf 3 1,272 Nov-07-2022, 01:30 PM
Last Post: philipbergwerf
  Precision conversion garynewport 2 1,058 Oct-19-2022, 10:47 AM
Last Post: garynewport
  KeyError: 0 when trying to dedupe and match records at scale Catalytic 1 2,307 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,429 May-07-2021, 12:39 AM
Last Post: MDRI
  Matplotlib scale julienhofmann 0 1,860 Apr-04-2021, 08:50 AM
Last Post: julienhofmann
Photo Filtering data and precision during calculations Scientifix 0 1,839 Mar-30-2021, 01:00 PM
Last Post: Scientifix
  High-Precision Board Voltage Reading from Python into PD Liam484 1 2,148 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