「Python Decimal」の版間の差分
ナビゲーションに移動
検索に移動
(ページの作成:「==Python Decimal== [Python] [http://python.secsup.org/?p=138 Python Osmosis] ===Decimal=== *from decimal で利用 *小数点以下の計算も正しく行う *ge…」) |
|||
1行目: | 1行目: | ||
==Python Decimal== | ==Python Decimal== | ||
− | [Python] | + | [[Python]] |
− | [http://python.secsup.org/?p=138 Python Osmosis] | + | [[http://python.secsup.org/?p=138 Python Osmosis]] |
===Decimal=== | ===Decimal=== | ||
18行目: | 18行目: | ||
**************************************************************** | **************************************************************** | ||
− | + | >>> from decimal import * | |
− | + | >>> Decimal('0.70') * Decimal('1.05') | |
Decimal('0.7350') | Decimal('0.7350') | ||
− | + | >>> .70 * 1.05 | |
0.73499999999999999 | 0.73499999999999999 | ||
− | + | >>> Decimal('1.00') % Decimal('.10') | |
Decimal('0.00') | Decimal('0.00') | ||
− | + | >>> 1.00 % 0.10 | |
0.09999999999999995 | 0.09999999999999995 | ||
− | + | >>> sum([Decimal('0.1')] * 10) == Decimal('1.0') | |
True | True | ||
− | + | >>> sum([0.1] * 10) == 1.0 | |
False | False | ||
− | + | >>> getcontext().prec = 36 | |
− | + | >>> Decimal(1) / Decimal(7) | |
Decimal('0.142857142857142857142857142857142857') | Decimal('0.142857142857142857142857142857142857') |
2020年2月15日 (土) 08:05時点における版
Python Decimal
Decimal
- from decimal で利用
- 小数点以下の計算も正しく行う
- getcontext().prec で有効桁数を設定
Python 2.6.3 (r263rc1:75186, Oct 2 2009, 20:40:30) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. **************************************************************** Personal firewall software may warn about the connection IDLE makes to its subprocess using this computer's internal loopback interface. This connection is not visible on any external interface and no data is sent to or received from the Internet. **************************************************************** >>> from decimal import * >>> Decimal('0.70') * Decimal('1.05') Decimal('0.7350') >>> .70 * 1.05 0.73499999999999999 >>> Decimal('1.00') % Decimal('.10') Decimal('0.00') >>> 1.00 % 0.10 0.09999999999999995 >>> sum([Decimal('0.1')] * 10) == Decimal('1.0') True >>> sum([0.1] * 10) == 1.0 False >>> getcontext().prec = 36 >>> Decimal(1) / Decimal(7) Decimal('0.142857142857142857142857142857142857')
© 2006 矢木浩人