Oihana PHP

floorValue.php

Table of Contents

Functions

floorValue()  : float
Rounds a number down to a count of decimal places.

Functions

floorValue()

Rounds a number down to a count of decimal places.

floorValue(int|float $value[, int $floatCount = 0 ]) : float

The floor of a number is the closest integer that is less than or equal to it.

A decimal number is almost never exact in memory : 8.2 * 100 holds 819.9999999999999, and a naive floor( $value * $r ) / $r drops to 8.19. The scaled value is therefore rounded to six decimals before the floor is taken : a scaled value within one millionth of an integer is treated as sitting exactly on it, so only a real shortfall pushes the result down.

Parameters
$value : int|float

The number to round.

$floatCount : int = 0

The number of decimal places to round down to. A negative count is read as 0.

Tags
example
use function oihana\core\maths\floorValue;

echo floorValue( 4.9876 )     ; // 4
echo floorValue( 4.9876 , 2 ) ; // 4.98
echo floorValue( 4.1234 , 3 ) ; // 4.123
echo floorValue( 8.2 , 2 )    ; // 8.2  — not 8.19 : the float noise is ignored
author

Marc Alcaraz (ekameleon)

since
1.0.0
Return values
float —

The rounded number.

On this page

Search results