You can use number_format():

return number_format((float)$number, 2, '.', '');

Example:

$foo = "105";
echo number_format((float)$foo, 2, '.', '');  // Outputs -> 105.00

This function returns a string.

Answer from Codemwnci on Stack Overflow
🌐
PHP
php.net › manual › en › function.round.php
PHP: round - Manual
Returns the rounded value of num to specified precision (number of digits after the decimal point).
🌐
W3Schools
w3schools.com › php › func_math_round.asp
PHP round() Function
Round numbers to two decimals: <?php echo(round(4.96754,2) . "<br>"); echo(round(7.045,2) . "<br>"); echo(round(7.055,2)); ?> Try it Yourself » · Round numbers using the constants: <?php echo(round(1.5,0,PHP_ROUND_HALF_UP) . "<br>"); echo(round(-1.5,0,PHP_ROUND_HALF_UP) .
Discussions

How do I force 2 decimal places?
Why do you say, "not display to 2 decimal places"? I assume that you mean you don't want it to turn into a string by using number_format($value, 2)... And if that's the case then I have to question WHY you are concerned with the trailing zero being dropped if it's not being displayed. The only time you should be worrying about that trailing zero is when displaying it, and that's when you should be using number_format($value, 2) More on reddit.com
🌐 r/PHPhelp
14
4
October 15, 2023
Format a number to at least 2 decimal places
Basically, the number fed to the ... than 2 decimals, allow more than 2 digits past the decimal. In other words, no rounding should be done. Hopefully I haven't thoroughly confused everyone at this point and maybe there really is no PHP function that can handle this (perhaps ... More on experts-exchange.com
🌐 experts-exchange.com
April 1, 2008
PHP How do I round down to two decimal places? - Stack Overflow
The answers about multiplying by 100, flooring, and dividing by 100 are the only ways that I know of that accomplish rounding to 2 decimals while always rounding down. More on stackoverflow.com
🌐 stackoverflow.com
Round of into two decimal places - PHP - SitePoint Forums | Web Development & Design Community
Hi… I encountered problem in rounding of numbers into two decimal places. here is my sample code: if($W4_STATUS == 1 AND $DEPENDENTS == 0 AND $TotEarn >= 7917 AND $TotEarn <= 12500) { $TAX = ($TotEarn - 7917); … More on sitepoint.com
🌐 sitepoint.com
0
April 18, 2012
🌐
GeeksforGeeks
geeksforgeeks.org › php › how-to-round-number-to-n-decimal-places-in-php
How to Round Number to n Decimal Places in PHP ? - GeeksforGeeks
July 23, 2025 - However, it can also be utilized to round numbers to a specific number of decimal places. ... <?php $number = 3.14559; // Round to 2 decimal places $roundNumber = number_format($number, 2); echo "Original Number: " .
🌐
Scaler
scaler.com › home › topics › php round() function
PHP round() function - Scaler Topics
March 18, 2024 - The returned value represents the ... the return value of round(): In this example, the round() function is applied to the number 3.14159 with a precision of 2 decimal places....
🌐
Reddit
reddit.com › r/phphelp › how do i force 2 decimal places?
r/PHPhelp on Reddit: How do I force 2 decimal places?
October 15, 2023 -

Is it possible to force a variable to 2 decimal places (not display to 2 decimal places)?

eg. $newcostprice = round($currentcostprice * 1.1,2);

This is fine for say 5.877 (5.88) but not for say 5.8034 (5.8)

How do I do it so it's always 2 decimal places even if the 2nd (or both!) are "0"?

🌐
Codecademy
codecademy.com › docs › php › math functions › round()
PHP | Math Functions | round() | Codecademy
September 10, 2023 - <?php · $roundedNumber = round(99.75); ... to clipboard · Copy to clipboard · The example below demonstrates the use of the round() function to convert a float to 2 decimal numbers....
🌐
Inspector
inspector.dev › home › how to round numbers in php
How to round numbers in PHP - Inspector.dev
February 4, 2025 - The round() function is a flexible tool for rounding numbers. It can round to the nearest integer or to a specified number of decimal places. Here’s the syntax: ... // Rounds to the nearest integer echo round(3.2); // Outputs: 3 // Rounds ...
Find elsewhere
🌐
GitHub
gist.github.com › christoferd › f0e52f33d848819351fe0187813f7862
PHP: Round a number down to two decimal places · GitHub
PHP: Round a number down to two decimal places · Raw · RoundDown2DemialPlaces.php · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
🌐
findnerd
findnerd.com › list › view › Different-ways-to-round-number-to-2-decimal-places-in-PHP › 13665
Different ways to round number to 2 decimal places in PHP
December 31, 2015 - Many times we need to format a ... values upto 2 decimal points.1. round() : round() function used to round a floating point number to an integer or to fixed number of decimal points.example :<?php$number = 278.264;echo ...
🌐
Quora
quora.com › With-PHP-how-do-you-round-a-float-to-show-two-or-just-as-many-decimal-places-as-needed-E-g-1-000027-is-1-00003-22-0-is-22-323-229-is-323-23-2445-98-is-2445-98-and-so-on
With PHP, how do you round a float to show two or just as many decimal places as needed? E.g. 1.000027 is 1.00003, 22.0 is 22, 323.229 is 323.23, 2445.98 is 2445.98, and so on. - Quora
Since we rounded the original numbers to 2 decimal places, the first has 3 significant digits and the second has only 2 significant digits, so our answer can only have 2 significant digits of accuracy. That would put the accuracy at the hundredth place and our result is: ... What will be the output of this PHP code " (<? PHP $n = array ("16", "interview Mania", 10, "4"); echo (array_sum ($n))?
🌐
Uptimia
uptimia.com › home › questions › how to show a number to two decimal places in php?
How To Show A Number To Two Decimal Places In PHP?
October 16, 2024 - $number = 123.456789; $rounded_number = round($number, 2); $formatted_number = number_format($rounded_number, 2, '.', ''); echo $formatted_number; // Outputs: 123.46 ... When working with floating-point numbers, be aware of potential precision ...
🌐
Schoolsofweb
schoolsofweb.com › home › php how-to › how to round a number to two decimal places in php?
How to Round a Number to Two Decimal Places in PHP? – Schools of Web
"<br />"; $number = .549;echo number_format($number, 2); ?> ... round() function rounds the first parameter (which is a float) to the number of digits after decimal point mentioned by the second parameter. <?php $number = 549.767; echo round($number, 2). "<br />"; $number = 549; echo round($number, ...
🌐
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 - If you wanted to round the previous example to a precision of 2 decimal points, you would write round(3.457, 2) instead, resulting in 3.46. ... There is also a third argument you can use called the “mode” which will let you control the way ...
🌐
Java2Blog
java2blog.com › home › php › format number to 2 decimal places in php
Format Number to 2 Decimal Places in PHP [4 ways] - Java2Blog
December 7, 2022 - To format a number to 2 decimal places in PHP, you can use the round() function and pass the number and 2 as arguments to the round() function.
🌐
Experts Exchange
experts-exchange.com › questions › 23284776 › Format-a-number-to-at-least-2-decimal-places.html
Solved: Format a number to at least 2 decimal places | Experts Exchange
April 1, 2008 - ,'') will round 2.5849494 to 2 decimals... that's not the intention. Get a FREE t-shirt when you ask your first question. We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
🌐
SitePoint
sitepoint.com › php
Round of into two decimal places - PHP - SitePoint Forums | Web Development & Design Community
April 18, 2012 - Hi… I encountered problem in rounding of numbers into two decimal places. here is my sample code: if($W4_STATUS == 1 AND $DEPENDENTS == 0 AND $TotEarn >= 7917 AND $TotEarn <= 12500) { $TAX = ($TotEarn - 7917);
🌐
Wyzant
wyzant.com › resources › ask an expert
Show a number to 2 decimal places? | Wyzant Ask An Expert
June 5, 2019 - What's the correct way to round a PHP string to 2 decimal places?