小数点以下の値の操作・四捨五入や切上げ、切捨て

Pythonで四捨五入や小数点以下のの切り捨てや切り上げ方法のサンプルコードを以下に記します。

htmlinsert(): The given local file does not exist or is not readable.

関連記事

動作確認環境

$ python --version
Python 2.7.3
$ lsb_release -d
Description:    Ubuntu 12.04.4 LTS

int

intにより小数点以下を切り捨て整数化します。

指定した場所で小数点値を四捨五入

roundを使って小数点の四捨五入を実現することができます。

切り捨て math.floor

mathモジュールのfloorを使って切り捨てを行います。

切り上げ math.ceil

mathモジュールのceilを使って切り上げを行います。

以上、小数点以下の値の操作・四捨五入や切上げ、切捨てのサンプルコードでした。

htmlinsert(): The given local file does not exist or is not readable.


トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2025-03-12 (水) 11:32:27