Knaph

Floating-point numbers

Numbers with a decimal point, stored in binary with about 16 significant digits - right for measuring, but slightly off for most decimal fractions, so never compared with ==.

Depth 1 · Foundation

You can use floats for measurements: / always gives a float, float(input()) reads one, round shows it to so many decimals (rounding exact halves to even), and you round only at the end.

Sign in to prove what you know with a short quiz, see how deep you've gone, and earn XP for it.

Sign in with Google

Depths of understanding

  1. 1

    Foundation

    You can use floats for measurements: / always gives a float, float(input()) reads one, round shows it to so many decimals (rounding exact halves to even), and you round only at the end.

  2. 2

    Deeper

    You know why 0.1 + 0.2 is not 0.3 - floats are binary fractions with 53 digits, so most decimals are stored a tiny bit off - and so compare floats with a tolerance, keep money in whole cents, and expect small errors to add up over many steps.

    Master depth 1 first

Your path here

What's still between you and Floating-point numbers, depth 1, in the order you can learn it.

  1. 1ProgramDepth 1 · Foundation · Program Basics
  2. 2ExpressionDepth 1 · Foundation · Program Basics
  3. 3Variables in codeDepth 1 · Foundation · Program Basics
  4. 4Program stateDepth 1 · Foundation · Program Basics
  5. 5Input and outputDepth 1 · Foundation · Program Basics
  6. 6Functions in codeDepth 1 · Foundation · Functions
  7. 7Return valuesDepth 1 · Foundation · Functions
  8. 8BooleansDepth 1 · Foundation · Control Flow
  9. 9ConditionalsDepth 1 · Foundation · Control Flow
  10. 10LoopsDepth 1 · Foundation · Control Flow
  11. 11Accumulator patternDepth 1 · Foundation · Control Flow
  12. 12Floating-point numbersDepth 1 · Foundation · Data Types

Where it fits