Home > Net >  Python - How can I get the largest decimal of two decimals
Python - How can I get the largest decimal of two decimals

Time:11-26

I have two values of type decimal i.e <class 'decimal.Decimal'> and <class 'decimal.Decimal'> and the numbers are

print(option.principal.amount, 'and', max_monthly_amount.amount)

Outputs

500000.00 and 500000

Getting max of the two values like this

option.principal.amount.max(max_monthly_amount.amount)

Returns

'decimal.Decimal' object has no attribute 'max_term'

CodePudding user response:

max(option.principal.amount, max_monthly_amount.amount))

Here's the docs to the standard library function

CodePudding user response:

you should convert both of them to float and then use max function this way :

num1 = float(option.principal.amount)
num2 = float(max_monthly_amount.amount)
print(max(num1, num2))
  • Related