Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

dart
floor
math
communitycreator

What is the floor() function in Dart?

Harris Amjad

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The floor() function in Dart returns the next largest integer that is less than or equal to a specified number.

The figure below shows the mathematical representation of the floor() function.

Mathematical representation of the "floor()" function

Syntax


number.floor()

Parameter

This function does not require a parameter.

Return value

The floor() function returns the next largest integer less than or equal to the number.

Code example

The code below demonstrates the use of the floor() function in Dart.

import 'dart:convert';
void main() {
//positive number
print("The value of (1.5).floor(): ${(1.5).floor()} ");
// negative number
print("The value of (-5.5).floor(): ${(-5.5).floor()} ");
//zero
print("The value of (0).floor(): ${(0).floor()}");
}

Explanation

  • Line 5: We calculate the floor value of the positive number 1.5 using floor().
  • Line 8: We calculate the floor value of the negative number -5.5 using floor().
  • Line 11: We calculate the floor value 0 using floor().

RELATED TAGS

dart
floor
math
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring