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. Answer from Diapolo10 on reddit.com
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.
🌐
TestDriven.io
testdriven.io › tips › c1f6f393-5fa2-4edd-8b64-cc1344219173
Tips and Tricks - Decimal vs float in Python | TestDriven.io
An example 👇 · from decimal import Decimal print(1.20 + 1.30) # => 2.5 print(Decimal("1.20") + Decimal("1.30")) # => 2.50 print(1.1 + 2.2) # => 3.3000000000000003 print(Decimal("1.1") + Decimal("2.2")) # => 3.3 ·
Discussions

floating point - Decimal Python vs. float runtime - Stack Overflow
So using decimal was about 200 times slower than using floats. Is this type of difference normal and along the lines of what I should expect when deciding which data type to use? ... I guess this is because the Python type float is somewhere deeply implemented in C, while decimal looks like ... 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
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
What's different between Decimal and Floating point numbers in Python?
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. More on reddit.com
🌐 r/learnpython
6
5
March 5, 2021
🌐
Python
docs.python.org › 3 › library › decimal.html
decimal — Decimal fixed-point and floating-point arithmetic
If value is a tuple, it should have three components, a sign (0 for positive or 1 for negative), a tuple of digits, and an integer exponent. For example, Decimal((0, (1, 4, 1, 4), -3)) returns Decimal('1.414'). If value is a float, the binary ...
🌐
LAAC Technology
laac.dev › blog › float-vs-decimal-python
Float vs Decimal in Python | LAAC Technology
March 4, 2021 - Once again, using floats causes precision issues. >>> from decimal import Decimal >>> Decimal(0.01) == Decimal("0.01") False · In this example, we expect these decimals to be equal, but, because of the precision issues with floats, this decimal equality test returns false.
🌐
The Teclado Blog
blog.teclado.com › decimal-vs-float-in-python
Decimal vs float in Python - The Teclado Blog
October 26, 2022 - So what happens when we write 0.1 in Python? Let's take a look: ... For those of you not familiar with the syntax above, the :.20f is a way of telling Python we want 20 digits after the decimal point for this float.
🌐
Medium
shiladityamajumder.medium.com › understanding-the-difference-between-float-and-decimal-in-python-18bae3b96ebc
Understanding the Difference Between float and decimal in Python | by Shiladitya Majumder | Medium
June 2, 2025 - In this article, we’ll dive deep into the difference between float and decimal.Decimal in Python, explore their use cases, and show practical examples to illustrate when and why you should use one over the other.
Find elsewhere
🌐
Codeforces
codeforces.com › blog › entry › 78645
Difference between Decimal and float in python - Codeforces
Difference between Decimal and float in python · By neo203, history, 5 years ago, For this task on Atcoder, from decimal import Decimal as dec a,b = map(dec,input().split()) print(int(a*b)) gives AC, but · a,b = map(float,input().split()) print(int(a*b)) gives WA.
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.

🌐
DevCamp
devcamp.com › trails › 28 › campsites › 214 › guides › decimal-vs-float-python
Decimal vs Float in Python
I'm going to show you the key differences between float's and decimals and then we can talk a little bit about when you'd want to use one over the other. And this is also going to give us a nice introduction on how we can import outside libraries. Even though decimal is inside a python we're going to have to explicitly call it because we can't simply use it the same way that we've used other functions leading up to this point. So before we get into anything let's come up with a few example ...
🌐
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.
🌐
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...
🌐
Luc
anh.cs.luc.edu › python › hands-on › 3.1 › handsonHtml › float.html
1.14. Decimals, Floats, and Floating Point Arithmetic — Hands-on Python Tutorial for Python 3
A useful example is the 0.5 power: it produces a square root. Try in the Shell: ... The result of a power operation is of int type only if both parameters are integers and the correct result is an integer. You generally do not want to display a floating point result of a calculation in its ...
🌐
Python documentation
docs.python.org › 3 › tutorial › floatingpoint.html
15. Floating-Point Arithmetic: Issues and Limitations — Python 3.14.3 documentation
Floating-point numbers are represented in computer hardware as base 2 (binary) fractions. For example, the decimal fraction 0.625 has value 6/10 + 2/100 + 5/1000, and in the same way the binary fraction 0.101 has value 1/2 + 0/4 + 1/8.
🌐
DEV Community
dev.to › kalebu › when-decimal-is-better-than-float-in-python-io6
When you should use Decimal over float in Python - DEV Community
May 12, 2021 - After a bit of googling, I came to realize that python does not store exact floating numbers but with tons of decimal other decimal precision(this has to do with the design of the language itself)
🌐
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 - This type employs a decimal floating-point model, representing numbers as a tuple of sign, coefficient, and exponent. This model allows for a more accurate representation of decimal numbers, particularly crucial in scenarios demanding precision, such as financial calculations. The crux of the matter lies in the comparison of a Python float (e.g., 10.17) with a value retrieved from a PostgreSQL database of type decimal.Decimal having the same apparent value (10.17).
🌐
EyeHunts
tutorial.eyehunts.com › home › python decimal vs float
Python decimal vs float - Tutorial - By EyeHunts
February 21, 2023 - from decimal import Decimal # Decimals print(Decimal('.1') + Decimal('.1') + Decimal('.1')) # Float print(.1 + .1 + .1) ... Using Python 2.7 on my system, the decimal module is ~180x slower.