zoukankan      html  css  js  c++  java
  • python 保存两位小数

     一、代码

    import decimal
    
    decimal.getcontext().rounding = decimal.ROUND_HALF_UP
    
    
    def index(number):
        n = str(number*100)
        n = decimal.Decimal(n).__round__(1)
        n = n / decimal.Decimal("100")
        n = decimal.Decimal(str(n), decimal.getcontext())
        return float(n.__round__(2))
    
    
    count = 0.015
    while count < 1:
        r = index(count)
        print(r, str(count), sep=' ----- ')
        count += 0.01
    

     二、结果

  • 相关阅读:
    小学期实践2
    小学期实践小组心得
    小学期实践1
    《构建之法》8
    《构建之法》7
    《构建之法》6
    《构建之法》5
    《构建之法》4
    《构建之法》3
    lintcode
  • 原文地址:https://www.cnblogs.com/dream4567/p/11015719.html
Copyright © 2011-2022 走看看