問:
python有什么函數(shù)可以進行精確度處理
答:
Python的定義允許使用不同的函數(shù)以多種方式處理浮點數(shù)的精度。其中大多數(shù)是在“ math”模塊下定義的。本文將討論一些最常用的函數(shù)。
1. trunc(): -此函數(shù)用于消除浮點數(shù)的所有小數(shù)部分,并返回不帶小數(shù)部分的整數(shù)。
2. ceil(): -此函數(shù)用于打印大于給定數(shù)字的最小整數(shù)。
3. floor(): -此函數(shù)用于打印小于給定整數(shù)的最大整數(shù)。
# Python code to demonstrate ceil(), trunc()
# and floor()
# importing "math" for precision function
import math
# initializing value
a = 3.4536
# using trunc() to print integer after truncating
print ("The integral value of number is : ",end="")
print (math.trunc(a))
# using ceil() to print number after ceiling
print ("The smallest integer greater than number is : ",end="")
print (math.ceil(a))
# using floor() to print number after flooring
print ("The greatest integer smaller than number is : ",end="")
print (math.floor(a))
輸出 :
The integral value of number is : 3
The smallest integer greater than number is : 4
The greatest integer smaller than number is : 3








暫無數(shù)據(jù)