Skip to main content
Filter by
Sorted by
Tagged with
3 votes
2 answers
64 views

Contrary to what the docs might suggest, create_decimal_from_float() does not always round to its specified precision. As the last line of the following example shows, when a near-zero value is passed ...
Qwerty-uiop's user avatar
0 votes
1 answer
115 views

Recently I got to know the decimal python module. While I got to understand how to work with this, I still have a question that persists: What is/are the main case(s) where coders should use decimal....
Jaime 's user avatar
  • 143
3 votes
2 answers
346 views

I have a DataFrame where some columns use the Decimal datatype. I'd like to export this data to an Excel spreadsheet, keeping the decimal/numeric format. However, my code is converting the columns to ...
LosProgramer's user avatar
1 vote
0 answers
90 views

so I'm trying to modify the precision used in my code. the only method (I know of) is using the "decimal" module. but I'm not really sure how to use it. I'm not entirely new to Python, but I'...
david's user avatar
  • 19
1 vote
2 answers
186 views

It is nice, easy and fast to use format-strings in python. So I never considered the performance penalty of this operation. Some time ago I switched my program from float data type to Decimal to ...
StarterKit's user avatar
1 vote
1 answer
795 views

I use the Python decimal module to get around the floating point error. And from what I understand, I can set how many decimal places the decimal can have by setting the precision in the context. But ...
Vladislav Korecký's user avatar
-1 votes
2 answers
144 views

Difference between rounding using Decimal library and rounding using round() function in Python 3. I don't know whether to use the round() function or use the Decimal library to round numbers Decimal ...
Mờ Tê's user avatar
0 votes
1 answer
93 views

I'm trying to fix all my calculation by using Python Decimal. I'm limiting the decimal places to 3, nevertheless, I'm getting this behavior: from decimal import * getcontext().prec = 3 In [0]:Decimal(...
João Gabriel Paina's user avatar
-1 votes
3 answers
1k views

I tried creating a temperature converter below: from decimal import * getcontext().prec = 10 celsius = Decimal(12) fahrenheit = celsius*9/5+32 kelvin = celsius+Decimal(273.15) romer = celsius*21/40+...
John's user avatar
  • 87
-2 votes
1 answer
138 views

>>> x = Decimal(1000) >>> y = Decimal(.005) >>> x * y Decimal('5.000000000000000104083408559') I expected the result to be just 5 >>> a = 1000 >>> b = ....
Dean Christian Armada's user avatar
1 vote
1 answer
897 views

I am wondering why mpmath is so much slower than decimal when doing the same operation for the same precision settings. from decimal import * from mpmath import * import timeit from decimal import ...
Yash Deshpande's user avatar
-1 votes
1 answer
251 views

hey so I am trying to calculate the amount of possible combinations of a 2000x2000 rubik's cube, and i written this code in python to calculate it, as online calculators i use and physical calculators ...
PA IN's user avatar
  • 1
0 votes
1 answer
213 views

I have a Python matrix and due to rounding issues in later parts of the code I would like to convert it to a matrix of Decimal elements. I am using Python3. How do I do that? My matrix is a = [ [0,...
SCBuergel's user avatar
  • 1,653
1 vote
2 answers
559 views

I'm interested in creating decimal.Decimal objects in an extension in C. I cannot find any documentation about this in the docs Does documentation for this exist? Are there any examples anywhere? I've ...
Bryant's user avatar
  • 3,681
0 votes
4 answers
2k views

I have a number from database (Clickhouse), and this number is limited with only two digits after comma on the database level. So I always have something like 34.23, 2323.23, 324234.3, and so one (in ...
Paul's user avatar
  • 6,837
0 votes
1 answer
84 views

Suppose I have an expression involving the decimal module where I want to input multiple values and get multiple values out. a=np.array([1,2,3]) b=np.array([4,5,6]) A=a.astype(object) B=b.astype(...
MysteriousBrit's user avatar
3 votes
2 answers
408 views

Why are these values different and how does it differ from each other? >>> from decimal import Decimal >>> Decimal('0.1') + Decimal('0.1') + Decimal('0.1') - Decimal('0.3') Decimal('...
Jose Angel's user avatar
4 votes
1 answer
5k views

To print a floating point number without exponential form, we can write like this: print('%f' % (10**-8)) But this generally displays zeroes due to precision error. Instead, we can use Decimal....
Meraj al Maksud's user avatar
21 votes
5 answers
19k views

Does anyone know of a faster decimal implementation in python? As the example below demonstrates, the standard library's decimal module is ~100 times slower than float. from timeit import Timer ...
Kozyarchuk's user avatar