Oihana PHP

ceilValue.php

Table of Contents

Functions

ceilValue()  : float
Rounds a number up to a count of decimal places.

Functions

ceilValue()

Rounds a number up to a count of decimal places.

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

The ceiling of a number is the closest integer that is greater than or equal to it.

A decimal number is almost never exact in memory : 1.1 * 100 holds 110.00000000000001, and a naive ceil( $value * $r ) / $r climbs to 1.11. The scaled value is therefore rounded to six decimals before the ceiling is taken : a scaled value within one millionth of an integer is treated as sitting exactly on it, so only a real excess pushes the result up.

Parameters
$value : int|float

The number to round.

$floatCount : int = 0

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

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

echo ceilValue( 4.1234 )    ; // 5
echo ceilValue( 4.1234 , 2 ) ; // 4.13
echo ceilValue( 4.9999 , 3 ) ; // 5
echo ceilValue( 1.1 , 2 )    ; // 1.1  — not 1.11 : the float noise is ignored
author

Marc Alcaraz (ekameleon)

since
1.0.0
Return values
float —

The rounded number.

On this page

Search results