Kotlin floor()

py9792289087's avatar
Published Oct 14, 2023
Contribute to Docs

The floor() function takes a value and returns the nearest integer that is lower than or equal to the value given.

The result returns a value type of float.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn Kotlin, the expressive, open-source programming language developed by JetBrains.
    • Beginner Friendly.
      9 hours

Syntax

import kotlin.math.*
floor(x)

Where x is the number of type double to be rounded down to the nearest integer.

Example

The following example demonstrates a basic implementation of the floor() method.

import kotlin.math.*
println(floor(3.4))

This will output:

3.0

The result will be a float value of 3 as the function rounds 3.4 down to 3.

All contributors

Contribute to Docs

Learn Kotlin on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn Kotlin, the expressive, open-source programming language developed by JetBrains.
    • Beginner Friendly.
      9 hours