I expect 0.5 to round up to 1. Can anybody explain why it rounds down to 0 instead?
>>> from decimal import *
>>> getcontext().prec = 0
>>> +Decimal(0.5)
Decimal('0')
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You asked for zero significant digits of precision. If you don’t allow any digits at all to be stored, all numbers will be zero.
Note that the precision is the number of significant decimal digits, that is, not counting leading zeros.
0.5has a single significant digit,1.5has two. Also note thatDecimaluses banker’s rounding.