CodeXpress

Welcome, Guest: Join CodeXpress Log In!

Stats: 11 Members, 99 topics and 9 posts Date:  Saturday 31 October 2020 at 10:58 PM

This is a product of CodeXpress Buy License for your website

PHP: Round a number upto 2 decimal places and if the number is a whole number then add trailing zeros

CodeXpress / Science/Technology / PHP 7x / PHP: Round a number upto 2 decimal places and if the number is a whole number then add trailing zeros

21 people viewed

Php: Round A Number Upto 2 Decimal Places And If The Number Is A Whole Number Then Add Trailing Zeros
(Go Down) (» Reply topic)
PHP: Round a number upto 2 decimal places and if the number is a whole number then add trailing zeros by Marshallunduemi(): Tue 07, July, 2020
Question


$number = 153.78999
$rounded_value = round($number,2);

$rounded_value will be 153.79

What i want is if

$number = 153

then

$rounded_value = 153.00

----------------------------------------------------------------------------------------------
Answers
----------------------------------------------------------------------------------------------
You can try like this:

sprintf("%0.2f",$number);


Check sprintf

or try like this:

$rounded_value = number_format($number,2);

Check number_format

Welcome to CodeXpress Forum Script - Download NL script Free
(» Go Up)

You must Sign in or Sign Up to post content

For you to post content on this website you have to log in or register, it only take few minute to create account

Go Up

Recommended for you

Php: Round A Number Upto 2 Decimal Places And If The Number Is A Whole Number Then Add Trailing Zeros

Currently: 1 guest(s) reading this article

Developed by Codexpress Programming Labs
Post content
Powered by Marshall