Trusted answers to developer questions

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.

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

Figure 1 shows the mathematical representation of the `floor()`

function.

Note: We need to import`Foundation`

in our code to use the`floor()`

function. We can import it like this:`import Foundation`

.

```
floor(number)
```

This function requires a number as a parameter.

The `floor()`

function returns the next largest integer less than or equal to the number set as a parameter.

The code written below demonstrates the use of the `floor()`

function in Swift:

import Swift//header for functionimport Foundation//integerprint ("The value of floor(4.0) : ",floor(4.0));//positive double valueprint ("The value of floor(2.56) : ",floor(2.56));//negative double valueprint ("The value of floor(-2.56) : ",floor(-2.56));

**Line 3**: We add the header `Foundation`

required for the `floor()`

function.

**Line 6**: We calculate the floor of the integer values using the `floor()`

function.

**Line 9**: We calculate the floor of the positive double value using the `floor()`

function.

**Line 12**: We calculate the floor of the negative double value using the `floor()`

function.

RELATED TAGS

swift

floor

math

communitycreator

CONTRIBUTOR

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.

Keep Exploring

Related Courses