Python math.trunc()メソッド
例
異なる数の整数部分を見つけます。
# Import math Library
import math
# Return the truncated integer
parts of
different numbers
print(math.trunc(2.77))
print(math.trunc(8.32))
print(math.trunc(-99.29))
定義と使用法
このmath.trunc()
メソッドは、数値の切り捨てられた整数部分を返します。
注:この方法では、数値を最も近い整数に切り上げ/切り下げませんが、小数点以下を削除するだけです。
構文
math.trunc(x)
パラメータ値
Parameter | Description |
---|---|
x | Required. The number you want to remove the decimal part of. If the value is not a number, it returns a TypeError |
技術的な詳細
戻り値: | 数値のint 切り捨てられた整数部分を表す値 |
---|---|
Pythonバージョン: | 1.4 |