Please enable JavaScript to use CodeHS

Intro to Computer Science in Python 3

Lesson 4.5 Floating Point Numbers and Rounding

Description

In this lesson, students learn about the intricacies of floating point numbers. When using comparison operators with floating point numbers in Python, we will sometimes see strange behavior because of bizarre rounding methods. When using a comparison operator with floating point numbers, you should use round(x) to avoid strange rounding behavior. round(x, n) will round the float x to n decimal places. round(x) will round the float x to 0 decimal places.


Objective

Students will be able to:

  • Use floating point numbers
  • Round values in their programs