python保留两位小数: In [1]: a = 5.026 In [2]: b = 5.000 In [3]: round(a,2) Out[3]: 5.03 In [4]: round(b,2) Out[4]: 5.0 In [5]: '%.2f' % a Out[5]: '5.03' In [6]: '%.2f' % b Out[6]: '5.00' In [7]: float('%.2f' % a) Out[7]: 5.03 In [8]: float('%.2f' % b) Out[
http://blog.csdn.net/windone0109/article/details/5355379进一法: 即省略的位上只要大于零都要进一位 : 四舍五入法: 即省略的位上小于五都要舍去,但省略的位上满五都要进一位 : 还有一种 去尾法: 即省略的位上不管是否满五都要舍去 : 1.除法带小数 例如: int a = 8; int b = 3; int c = ((double)la)/b; System.out.println(c); 系统打印:2.666666666
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>floatDecimal.html</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta htt
一.代码 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.