This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Huan
Recipients Huan, umedoblock, valhallasw, zach.ware
Date 2017-07-30.09:00:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1501405200.93.0.756387412251.issue24827@psf.upfronthosting.co.za>
In-reply-to
Content
Hello,
I was confused by the decimal module. The problem is that I want to 

from decimal import Decimal, ROUND_HALF_UP
def rounded(number, n):
    ''' Round the digits after the n_th decimal point by using
    decimal module in python.
    
    For example:
    2.453 is rounded by the function of deal_round(2.453, 1),
    it will return 2.5.
    2.453 is rounded by the function of deal_round(2.453, 2),
    it will return 2.45.
    '''
    val = Decimal(number)
    acc = str(n)  # n = 0.1 or 0.01 or 0.001
    return Decimal(val.quantize(Decimal(acc), rounding=ROUND_HALF_UP))

for x in np.arange(1.0, 4.01, 0.01):
    rounded_val = rounded(x, 0.1)
    print("{:}\t{:}".format(x, rounded_val))



The results obtained from the numpy array looks fine, but if I directly used rounded(1.45, 0.1), it yielded Decimal('1.4'), rather than Decimal('1.5').


I think it would be a bug.
History
Date User Action Args
2017-07-30 09:00:01Huansetrecipients: + Huan, valhallasw, umedoblock, zach.ware
2017-07-30 09:00:00Huansetmessageid: <1501405200.93.0.756387412251.issue24827@psf.upfronthosting.co.za>
2017-07-30 09:00:00Huanlinkissue24827 messages
2017-07-30 09:00:00Huancreate