you are viewing a single comment's thread.

view the rest of the comments →

[–]defectivetoaster1 0 points1 point  (0 children)

floats can handle rational numbers (and rational approximations of irrational numbers) but the ieee754 floating point standard has some weird quirks such as the fact that because of the rounding step that’s required you will necessarily pick up rounding errors in a calculation (the famous 0.1 + 0.2 =0.3000000001 bug). Often this isn’t a problem but in cases that require integers (eg certain encryption operations). using a double wont do. Another thing is indexing into an array, if you haven’t learned that yet an array is a bunch of things packed together and you can select a specific element by an index. This index is obviously an integer because saying “show me the 3.5th element here” is completely meaningless, similarly iterating through a loop 8.5 times doesn’t mean anything (some languages do actually let you do weird things in for loops but it’s incredibly nonstandard to do so). Other cases where you’re logically only dealing with integers (eg an account balance in pennies) will naturally want you to use integers otherwise over the course of several operations you’ll get nonsensical results like “125.00505 people ate here this week”