[英]Python - How can I get the largest decimal of two decimals
I have two values of type decimal ie <class 'decimal.Decimal'> and <class 'decimal.Decimal'>
and the numbers are我有两个十进制类型的值,即
<class 'decimal.Decimal'> and <class 'decimal.Decimal'>
数字是
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'
max(option.principal.amount, max_monthly_amount.amount))
Here's the docs to the standard library function这是标准库 function 的文档
you should convert both of them to float and then use max function this way:您应该将它们都转换为浮点数,然后以这种方式使用 max function :
num1 = float(option.principal.amount)
num2 = float(max_monthly_amount.amount)
print(max(num1, num2))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.