you have 3 possibility : round(), floor(), ceil()

for you :

$step = 2; // number of step 3th digit
$nbr = round(2.333333333 * $step, 1) / $step; // 2.35

$step = 4; // number of step on 3th digit
$nbr = round(2.333333333 * $step, 1) / $step; // 2.325

round

<?php
echo round(3.4);         // 3
echo round(3.5);         // 4
echo round(3.6);         // 4
echo round(3.6, 0);      // 4
    echo round(1.95583, 2);  // 1.96
echo round(1241757, -3); // 1242000
echo round(5.045, 2);    // 5.05
echo round(5.055, 2);    // 5.06
?>

floor

<?php
echo floor(4.3);   // 4
echo floor(9.999); // 9
echo floor(-3.14); // -4
?>

ceil

<?php
echo ceil(4.3);    // 5
echo ceil(9.999);  // 10
echo ceil(-3.14);  // -3
?>
Answer from Alban on Stack Overflow
🌐
PHP
php.net › manual › en › function.round.php
PHP: round - Manual
Using PHP_ROUND_HALF_UP with 1 decimal digit precision float(1.6) float(-1.6) Using PHP_ROUND_HALF_DOWN with 1 decimal digit precision float(1.5) float(-1.5) Using PHP_ROUND_HALF_EVEN with 1 decimal digit precision float(1.6) float(-1.6) Using PHP_ROUND_HALF_ODD with 1 decimal digit precision float(1.5) float(-1.5)
🌐
W3Schools
w3schools.com › php › func_math_round.asp
PHP round() Function
Loops While Loop Do While Loop For Loop Foreach Loop Break Statement Continue Statement PHP Functions PHP Arrays · Arrays Indexed Arrays Associative Arrays Create Arrays Access Array Items Update Array Items Add Array Items Remove Array Items Sorting Arrays Multidimensional Arrays Array Functions PHP Superglobals
🌐
Codecademy
codecademy.com › docs › php › math functions › round()
PHP | Math Functions | round() | Codecademy
September 10, 2023 - Returns the nearest whole number to the passed value, or the value rounded to the specified decimal precision.
🌐
Scaler
scaler.com › home › topics › php round() function
PHP round() function - Scaler Topics
March 18, 2024 - We use the round() function with a precision of 3 and the PHP_ROUND_HALF_UP constant to round the number up to three decimal places, resulting in 3.142. To ensure that the output is formatted with exactly three decimal places, we then use the ...
🌐
PHP.Watch
php.watch › versions › 8.4 › round-new-modes
New rounding modes in `round()` function - PHP 8.4 • PHP.Watch
PHP_ROUND_HALF_DOWN: Rounds the number towards zero when it is halfway there, making 1.5 into 1 and -1.5 into -1. Constant value int(2). PHP_ROUND_HALF_EVEN: Rounds the number towards the nearest even value when it is halfway there, making both 1.5 and 2.5 into 2.
Find elsewhere
🌐
CalculatorSoup
calculatorsoup.com › calculators › math › roundingnumbers.php
Rounding Numbers Calculator
Rounding calculator to round numbers up or down to any decimal place. Choose ones to round a number to the nearest dollar.
🌐
Inspector
inspector.dev › home › how to round numbers in php
How to round numbers in PHP
February 4, 2025 - This mode (PHP_ROUND_HALF_UP) rounds midpoint values away from zero, treating positive and negative numbers symmetrically.
🌐
W3Schools
www-db.deis.unibo.it › courses › TW › DOCS › w3schools › php › func_math_round.asp.html
PHP round() Function
Tip: To round a number UP to the nearest integer, look at the ceil() function. Tip: To round a number DOWN to the nearest integer, look at the floor() function. ... <?php echo(round(4.96754,2) . "<br>"); echo(round(7.045,2) .
🌐
GeeksforGeeks
geeksforgeeks.org › php › php-round-function
PHP round( ) Function - GeeksforGeeks
June 22, 2023 - PHP_ROUND_HALF_UP: This mode tells to round up the number specified by parameter $number by precision specified by parameter $precision away from zero.
🌐
Reddit
reddit.com › r/lolphp › round() doesn't actually round
r/lolphp on Reddit: round() doesn't actually round
May 15, 2013 -

I had a bug in a payment system where the paypal payment amounts don't add up. I looked into it, and the amounts were something like 18.799999999999

apparently, someone used round($amount, 2) and expected PHP to actually round the number to two digits

For certain float values that just doesn't work. I found an example like this:

echo round(-0.07, 2); //-0.07000000000000001

this is what happens when your precision is set to 17

of course my code uses number_format, but I expected round() to... round the floats? Silly me, I'm using PHP, the language guided by the Principle of Highest Perplexity

🌐
Codeguage
codeguage.com › v1 › courses › php › numbers-rounding-numbers
PHP Rounding Numbers
In this unit, we'll explore the world of numbers in PHP. We'll get to know about the internal representation of integers and floats, the exponential notation and the symbol E, how to round numbers, how to obtain random integers and much more.
🌐
Nestify
nestify.io › blog › up-down-round-values-in-php-ceil-floor-functions
Up and Down Round values in PHP: ceil, floor and round functions: The ultimate tutorial 2024
December 25, 2023 - Read Also: Best PHP Libraries Every Developer Should Make Use Of · Unlike ceil() and floor(), which automatically round up or down, the Round Values In PHP (’round()’ function) rounds a number to the nearest integer when no precision is supplied.
🌐
HashBangCode
hashbangcode.com › article › rounding-and-displaying-numbers-php
Rounding And Displaying Numbers In PHP | #! code
To round a number in PHP you can ... are round(), ceil() and floor(). All of these functions take number as the input and will round the value depending on the function used. To round to the closest integer use the round() function. round(4.4); // returns 4 · To round down to the nearest whole number use the floor() function. floor(4.4); // returns 4 · To round up to the nearest whole number use the ceil() function...
🌐
SBZ Systems
sbzsystems.com › support issues › decimal round up (php)
Decimal Round Up (PHP) - SBZ Systems
November 20, 2021 - To round decimals upwards: function round_up ( $value, $precision ) { $pow = pow ( 10, $precision ); return ( ceil ( $pow * $value ) + ceil ( $pow *
🌐
W3Schools
w3schools.com › php › func_math_ceil.asp
PHP ceil() Function
Tip: To round a floating-point number, look at the round() function. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if ...
🌐
Hacking with PHP
hackingwithphp.com › 4 › 6 › 1 › rounding
Rounding: ceil(), floor(), and round() – Hacking with PHP - Practical PHP
As you can see, 4.5 is rounded up to 5, whereas 4.4999 is rounded down to 4. Line four has parameter two being used for the first time, which shows that it is very easy to round to a given number of decimal places. Note that in line five we get 4.1235 when rounding to four decimal places, because PHP looks one digit further to decide on the last digit.
🌐
Linux Tip
linuxscrew.com › home › programming › php › how to round numbers (integer, decimals) in php with the round() function
How to Round Numbers (Integer, Decimals) in PHP with the round() Function
November 18, 2021 - This article will show you how to round numbers in PHP with the round() function, including rounding to the nearest integer or a set number of decimal places.
🌐
DEV Community
dev.to › morinoko › rounding-numbers-in-php-with-round-2e8b
PHP Round Number: Rounding Numbers in PHP with round() - DEV Community
October 28, 2018 - PHP’s round() function takes a decimal number (a.k.a. floating point number) and rounds up or down. In its most simple and default form, it will round the decimal to the nearest whole number.