Latest web development tutorials

PythonのMODF()関数

Pythonの数値 Pythonの数値


説明

MODF()メソッドは、整数部と同じxを持つ2つの部分、浮動小数点表現の整数部の値のX、記号の小数部を返します。


文法

次の構文MODF()メソッドです。

import math

math.modf( x )

注:MODF()は直接アクセスできません、あなたは数学のモジュールをインポートする必要があり、静的オブジェクトを介してメソッドを呼び出します。


パラメータ

  • X - 数値式。

戻り値

整数部とxの小数部を返し、

以下は、MODF()メソッドの使用例を示します。

#!/usr/bin/python
import math   # This will import math module

print "math.modf(100.12) : ", math.modf(100.12)
print "math.modf(100.72) : ", math.modf(100.72)
print "math.modf(119L) : ", math.modf(119L)
print "math.modf(math.pi) : ", math.modf(math.pi)

上の例の出力を実行した後です。

math.modf(100.12) :  (0.12000000000000455, 100.0)
math.modf(100.72) :  (0.71999999999999886, 100.0)
math.modf(119L) :    (0.0, 119.0)
math.modf(math.pi) :  (0.14159265358979312, 3.0)

Pythonの数値 Pythonの数値