需要计算的数字是n。
1.整取math.ceil (n )
2.拆下math.floor (n )或(/)分子//分母)
3 .四舍五入为:round(n,digits ),digits表示保留小数点后的位数,不进行填充而直接四舍五入,如果取0,则表示为整数的浮点数
4 .舍弃小数部分直接取整数部分:math.trunc(n )或int (n )
代码:
n=-17/3导入矩阵#所有print(math.ceil ) n ) #四舍五入print ) round(N ) n,round(N,0 ) )所有print (math.floor )
PS: Python版本: 3.10,编辑器: vs代码