トップ 一覧 ping 検索 ヘルプ RSS ログイン

Python Decimalの変更点

  • 追加された行はこのように表示されます。
  • 削除された行はこのように表示されます。
!!!Python Decimal
[Python]
Python Osmosis 
*http://python.secsup.org/?p=138
[Python Osmosis|http://python.secsup.org/?p=138]

!!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')