๐ŸŒ
LAAC Technology
laac.dev โ€บ blog โ€บ float-vs-decimal-python
Float vs Decimal in Python | LAAC Technology
March 4, 2021 - Decimals can suffer from their own precision issues, but generally, decimals are more precise than floats. The performance difference between float and decimal, with Python 3, is not outlandish, and in my experience, the precision benefits of ...
๐ŸŒ
The Teclado Blog
blog.teclado.com โ€บ decimal-vs-float-in-python
Decimal vs float in Python
October 26, 2022 - The second issue is perhaps more pressing, however, and that's down to performance. decimal operations are likely to be around 3 times slower than operations using floats, so if you're dealing with a performance sensitive part of your application, ...
Discussions

which data type should I use for most accurate calculations? float decimal or python?
Floats are great but unreliable - they have small imprecisions that can quickly add up. More on reddit.com
๐ŸŒ r/learnpython
7
1
March 25, 2023
floating point - Decimal Python vs. float runtime - Stack Overflow
Just a general question on what sort of runtime differences I should be expecting between using these two different data types. My test: test = [100.0897463, 1.099999939393,1.37382829829393,29. More on stackoverflow.com
๐ŸŒ stackoverflow.com
code golf - Float vs Decimal - Code Golf Stack Exchange
But I'll change it to Python and include the import, so people see your Python answer is 1 byte shorter. :) \$\endgroup\$ ... "The obvious" as in using Decimal for the comparison. Only golfy idea is replacing float() by eval() to save 1 byte. More on codegolf.stackexchange.com
๐ŸŒ codegolf.stackexchange.com
August 29, 2025
Floating-point numbers
The result of 12+12.23 is 35.120000000000005 The result of 23+12.23 is 35.230000000000004 And the result of 1.2-1 is 0.19999999999999996 But in C++ the results are true. Why?What is the difference between C++ and Python at floating-point numbers Note: The result of 0.1+0.1 is 0.2 It is true.But ... More on discuss.python.org
๐ŸŒ discuss.python.org
0
December 17, 2022
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ decimal.html
decimal โ€” Decimal fixed-point and floating-point arithmetic
Source code: Lib/decimal.py The decimal module provides support for fast correctly rounded decimal floating-point arithmetic. It offers several advantages over the float datatype: Decimal โ€œis based...
Top answer
1 of 8
7

Java, 80 79 59 57 bytes

s->s.compareTo(new java.math.BigDecimal(new Float(s))+"")

Outputs a negative integer if the internal floating point value is larger; 0 if they're the same; and a positive integer if the floating point is smaller.

Try it online.

Explanation:

s->                          // Method with String parameter and integer return
  s.compareTo(               //  Compare the input to (resulting in neg/0/pos):
   new java.math.BigDecimal( //   Create a BigDecimal, with value:
    new Float(s))            //    The (32-bit) floating point number of the input
   +"")                      //   Convert that BigDecimal to a String

Minor note: I've used Float (which is 32 bits) and therefore holds slightly different values than in the challenge description. If I would change it to Double (which is 64 bits) the values would be the same as the challenge description. This difference can for certain inputs also result in different outputs (e.g. the "0.09" is 0.0900000035762786865234375 as float, resulting in -23, but 0.0899999999999999966693309261245303787291049957275390625 as double, resulting in 1). The overall functionality would still be the same, though:
Try it online.

2 of 8
5

Vyxal 3, 1 byte

1

Vyxal It Online!

Outputs 1 if equivalent, 0 if bigger, -1 if smaller. This probably polyglots a lot of languages lol. Leave a comment if you have a polyglot language where the answer is always 1.

Notably, this always outputs 1. That's because all numbers are stored exactly by default. That's an intentional language design decision we went out of our way to accommodate by using a third party library under the hood. Technically, the number type is called VNum which extends spire.Complex[Real], so not a "decimal" type but a type that happens to also be able to store decimals exactly by consequence of also storing things like surds exactly.

There's a slight chance this could be considered invalid by the "don't use decimal type" restriction, but that's up to the challenge asker as to whether the default (and only) generic number type being exact is allowed.

๐ŸŒ
LinkedIn
linkedin.com โ€บ pulse โ€บ navigating-nuances-numeric-precision-deep-dive-python-utkarsh-singh-ccemc
Navigating the Nuances of Numeric Precision: A Deep Dive into Python Floats and Decimals
December 7, 2023 - At the foundation of Pythonโ€™s numeric system lies the float type, adhering to the IEEE 754 standard for floating-point arithmetic. This standard provides a standardized binary representation of real numbers. However, due to the inherent limitations of binary representation, rounding errors can occur, introducing imprecision in certain scenarios. In response to precision concerns associated with float, the decimal module introduces the Decimal type.
Find elsewhere
๐ŸŒ
Jakeboxer
jakeboxer.com โ€บ blog โ€บ 2009 โ€บ 03 โ€บ 17 โ€บ benchmarking-python-decimal-vs-float
Benchmarking Python decimal vs. float - jBoxer
This time, the float version averaged about 0.6 seconds (1.15 with 40,000 iterations instead of 20,000), while the decimal version averaged over 11 seconds (23 with 40,000 iterations instead of 20,000). So while Python float creation and printing is merely 3x as fast as Python decimal creation and printing, Python float division is almost 20x as fast as Python decimal division.
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Floating-point numbers - Python Help - Discussions on Python.org
December 17, 2022 - The result of 12+12.23 is 35.120000000000005 The result of 23+12.23 is 35.230000000000004 And the result of 1.2-1 is 0.19999999999999996 But in C++ the results are true. Why?What is the difference between C++ and Python at floating-point numbers Note: The result of 0.1+0.1 is 0.2 It is true.But the result of 1.2-1 is false
Top answer
1 of 4
9
Integers (int type) are "whole numbers", without the fractional part, eg. 10. You use this type when the value is always an integer, e.g. a counter. Floating point numbers (float type) can have fractional part, e.g. 10.1234. They are stored using the closest representation in binary notation. Most numbers cannot be represented accurately, so they are slightly off. You use float for most mathematical calculations involving fractional numbers. Decimal numbers (Decimal type in Python) are used to represent floating point numbers accurately, with a defined precision (a defined number of places after decimal point). They are represented with two integer numbers, one for the integer part and one for the fractional part. For example. 10.1234 is stored as (10, 1234). Decimal type is required when fractional numbers must be represented accurately, with defined precision. The most notable example is financial calculations. Using float type you may get a result of a financial operation as 1010.123456$. But money is expressed with at most two decimal places. What does 0.123456$ mean? You can round it to 1010.12$, but then what happens with the remaining 0.003456$? Some "smart" programmers used that to their advantage in the past and they made a lot of money (which they eventually had to give back). So, for money calculations, you should use Decimal type. A good explanation of the Decimal type is in the documentation: https://docs.python.org/3/library/decimal.html
2 of 4
7
Python's integers (ยฑ0, 1, 2, etc.) have unlimited accuracy, which is unusual as far as programming languages go. In most languages they usually cap at 64-bits (aka long int) and there may be multiple integer types of various sizes. This makes Python very useful for scientific computing as you don't need a separate BigNum library to handle arbitrary precision. Python's floating-point numbers don't quite have this same luxury due to the inaccurate nature of them. Since many decimal numbers cannot be accurately represented in binary, floating-point math will always run into inaccuracies. For instance, 0.1 + 0.1 + 0.1 isn't 0.3, but something like 0.3000000000001. You'll use floats whenever whole numbers aren't enough, but you don't need a specific amount of accuracy. You probably never meant to ask about this, but decimal.Decimal is an alternative to float that lets you set its precision yourself. It's still not infinitely accurate, but it's often used in scientific computing where integers just can't cut it.
๐ŸŒ
Medium
pranaysuyash.medium.com โ€บ how-i-lost-10-000-because-of-a-python-float-and-how-you-can-avoid-my-mistake-3bd2e5b4094d
Python Decimal vs Float: The $10,000 Mistake to Avoid | Medium
April 9, 2025 - Discover why using Python's float for financial calculations can be disastrous, and learn how to properly handle money with the Decimal module to avoid costly errors.
๐ŸŒ
Quora
quora.com โ€บ What-exactly-is-the-difference-between-decimals-floating-point-numbers-and-doubles-in-Python-programming-They-seem-to-get-addressed-interchangeably
What exactly is the difference between decimals, floating-point numbers and doubles in Python programming? They seem to get addressed interchangeably. - Quora
Answer (1 of 3): There is no such thing as doubles in Python itself, but Internally a floating point value is stored in a double precision C floating point value (as defined by IEEE 754 [1]) Floating point values are limited precision - they use a fixed number of bits to store a wide range of va...
๐ŸŒ
TestDriven.io
testdriven.io โ€บ tips โ€บ c1f6f393-5fa2-4edd-8b64-cc1344219173
Tips and Tricks - Decimal vs float in Python | TestDriven.io
Python tip: You can use Decimal instead of float to: incorporate a notion of significant places (1.20 + 1.30 = 2.50) represent decimal numbers exactly (1.1 + 2.2 = 3.3) In short, use Decimal when precision matters.
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ tutorial โ€บ floatingpoint.html
15. Floating-Point Arithmetic: Issues and Limitations โ€” Python 3.14.3 documentation
In the same way, no matter how many base 2 digits youโ€™re willing to use, the decimal value 0.1 cannot be represented exactly as a base 2 fraction. In base 2, 1/10 is the infinitely repeating fraction ยท 0.0001100110011001100110011001100110011001100110011... Stop at any finite number of bits, and you get an approximation. On most machines today, floats are approximated using a binary fraction with the numerator using the first 53 bits starting with the most significant bit and with the denominator as a power of two.
๐ŸŒ
freeCodeCamp
forum.freecodecamp.org โ€บ python
Floating point numbers to two decimal places - possible with standard lib? - Python - The freeCodeCamp Forum
August 24, 2022 - Iโ€™m trying to get 2 decimal places of 0s (e.g, 9.00) in the budget app project. I tried using string formatting, but the program expects a floating point number, not a string. Casting it to a float results in a single .0 because thatโ€™s how floating point numbers work in Python - that gets rejected, the program wants two 0s.
๐ŸŒ
Dynamo
forum.dynamobim.com โ€บ revit
Python rounding float value : adapting code in other code. (loop, function) - Revit - Dynamo
September 29, 2018 - EDIT: i found a new possible way perhaps. Jump to post 21 for that ๐Ÿ™‚ My Excel is dutch =AFRONDEN() means =ROUND() The Python values: value 1 = 13 decimals value 2 = 100 + value 1 (it should still have 13 decimals, but it seems to round) if i do the same in Excel it seems to make the same ...
๐ŸŒ
Hacker News
news.ycombinator.com โ€บ item
I've said this before, but I wish python and other high level languages defaulte... | Hacker News
February 11, 2023 - That's actually a really interesting question - while this is obviously true for most functions which (in a mathematical sense) exist, I wonder if it's true for "all functions weighted by their use in computing applications"? That is - do boring old "addition, subtraction, and multiplication ...
๐ŸŒ
Flexiple
flexiple.com โ€บ python โ€บ convert-decimal-float-python
Converting Decimal to Float in Python - Flexiple
March 22, 2024 - The decimal data type, available in the "decimal" module, offers high precision and is ideal for financial applications where accuracy is critical. It ensures the exact representation of numbers and avoids the inaccuracies associated with floating-point numbers. On the other hand, the float data type is the built-in floating-point representation in Python.
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Questions about the Python Language and Floating Point - Python Help - Discussions on Python.org
December 6, 2022 - -Does Python have floating point errors with its float number type? -If it does, is there any switch or kind of software option to turn off these error possibilities, at the level of the language? -I have heard that Pโ€ฆ