python Programming Glossary: decimal.decimal
In-memory size of python stucture http://stackoverflow.com/questions/1331471/in-memory-size-of-python-stucture tuple ... list list ... str a ... unicode u a ... decimal decimal.Decimal 0 ... object object ... for k v in sorted d.iteritems ... print..
Python JSON serialize a Decimal object http://stackoverflow.com/questions/1960516/python-json-serialize-a-decimal-object def _iterencode self o markers None if isinstance o decimal.Decimal # wanted a simple yield str o in the next line # but that would..
How to define a decimal class holding 1000 digits in python? http://stackoverflow.com/questions/19980840/how-to-define-a-decimal-class-holding-1000-digits-in-python This number using decimal.Decimal shows like this from decimal import Decimal as dc x dc 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113.. Example decimal.setcontext decimal.Context prec 1000 pi decimal.Decimal '3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113'..
Decimal place issues with floats and decimal.Decimal http://stackoverflow.com/questions/286061/decimal-place-issues-with-floats-and-decimal-decimal place issues with floats and decimal.Decimal I seem to be losing a lot of precision with floats. For example.. a float powers seem to work fine. import decimal print decimal.Decimal 1.2 2 1.44 The module documentation explains the need for and.. module documentation explains the need for and usage of decimal.Decimal pretty clearly you should check it out if you haven't yet. ..
python floating number http://stackoverflow.com/questions/2986150/python-floating-number ideal. For example 3.14 3.1400000000000001 import decimal decimal.Decimal '3.14' print decimal.Decimal '3.14' 3.14 # change the precision.. import decimal decimal.Decimal '3.14' print decimal.Decimal '3.14' 3.14 # change the precision decimal.getcontext .prec.. 3.14 # change the precision decimal.getcontext .prec 6 decimal.Decimal 1 decimal.Decimal 7 Decimal '0.142857' decimal.getcontext .prec..
Gauss-Legendre Algorithm in python http://stackoverflow.com/questions/347734/gauss-legendre-algorithm-in-python with_statement import decimal def pi_gauss_legendre D decimal.Decimal with decimal.localcontext as ctx ctx.prec 2 a b t p 1 1 D 2..
Removing Trailing Zeros in Python http://stackoverflow.com/questions/5807952/removing-trailing-zeros-in-python import decimal import random def format_number num try dec decimal.Decimal num except return 'bad' tup dec.as_tuple delta len tup.digits..
How to convert Python decimal to SQLite numeric? http://stackoverflow.com/questions/6319409/how-to-convert-python-decimal-to-sqlite-numeric example code from the docs import sqlite3 import decimal D decimal.Decimal def adapt_decimal d return str d def convert_decimal s return..
numpy array with dtype Decimal? http://stackoverflow.com/questions/7770870/numpy-array-with-dtype-decimal Decimal dtypes available in numpy import decimal numpy d decimal.Decimal '1.1' s '123.123' '23' '2323.212' '123123.21312' ss numpy.array.. '123123.21312' ss numpy.array s dtype numpy.dtype decimal.Decimal a numpy.array s dtype float type d class 'decimal.Decimal' type.. decimal.Decimal a numpy.array s dtype float type d class 'decimal.Decimal' type ss 1 1 class 'str' type a 1 1 class 'numpy.float64' I..
|