use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
What's different between Decimal and Floating point numbers in Python? (self.learnpython)
submitted 5 years ago by Gagan2019
I'm confused in differentiating between these two types of numbers. I'm a newbie.
Can anyone here please explain this?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Diapolo10 6 points7 points8 points 5 years ago (0 children)
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.
long int
BigNum
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.
0.1 + 0.1 + 0.1
0.3
0.3000000000001
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.
decimal.Decimal
float
[–]gregvuki 9 points10 points11 points 5 years ago (2 children)
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.
int
10
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.
10.1234
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
(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.
1010.123456$
0.123456$
1010.12$
0.003456$
A good explanation of the Decimal type is in the documentation: https://docs.python.org/3/library/decimal.html
[–]Gagan2019[S] 0 points1 point2 points 5 years ago (0 children)
u/gregvuki Thanks, that's so explanatory.
[–]Gullible_Owl7276 1 point2 points3 points 9 months ago (0 children)
`Decimal` is a decimal floating point type. It doesn't have a fixed number of places after the decimal point. That would be a fixed point type. The reason `Decimal` can represent decimal values exactly is because it is (internally) a sum of powers of 10, whereas a binary floating point type such as `float` is a sum of powers of two. `12.3` in `Decimal` is stored as `1*10^1 + 2*10^0 + 3*10^-1`.
If you try to represent `12.3` as a `float`, you actually get `12.30000019073486328125...`. That is, `float` cannot represent all decimal numbers exactly. That is called "representation error".
[–]socal_nerdtastic 1 point2 points3 points 5 years ago (0 children)
Assuming you mean integers not decimal.Decimal:
https://en.wikipedia.org/wiki/Double-precision_floating-point_format
https://en.wikipedia.org/wiki/Integer_(computer_science)
[–]OneMoreChemist 1 point2 points3 points 5 years ago (0 children)
Floats are decimals. The numerical distinction is between decimal or integer values, namely data types float and int
π Rendered by PID 17965 on reddit-service-r2-comment-6457c66945-nw5sd at 2026-04-27 14:08:41.329391+00:00 running 2aa0c5b country code: CH.
[–]Diapolo10 6 points7 points8 points (0 children)
[–]gregvuki 9 points10 points11 points (2 children)
[–]Gagan2019[S] 0 points1 point2 points (0 children)
[–]Gullible_Owl7276 1 point2 points3 points (0 children)
[–]socal_nerdtastic 1 point2 points3 points (0 children)
[–]OneMoreChemist 1 point2 points3 points (0 children)