ParthModi's avatar

How to get same value after two decimal point in PHP

my Output is

3.289

i want two decimal point but out will be same like

3.28

it's shoude not to incesss if last digit more then 5 using PHP

0 likes
6 replies
ParthModi's avatar

@Dragon_Worrior Hello I used it but its give me value like

3.29

but i wnat

3.28

number_format & round function incress number when last digit is more then 5

dacfabre's avatar
dacfabre
Best Answer
Level 3

@parthmodi number_format(floor($number*100)/100, 2);

$number*100 will make it 328.9 then floor it to remove the remaining decimal. then divide it to 100 to make it decimal again like 3.28 number_format() is optional. its to make sure we are getting 2 decimal

ParthModi's avatar

@dacfabre

Hello Your formula is working but its affected to my another record this my record screen short

https://prnt.sc/YBx2yqcmeDdW

after apply your formula screen short

https://prnt.sc/TKHmO9MPlUb_
dacfabre's avatar

@ParthModi like i said, number_format() is optional. if you want 0 to be not included, like in 0.1 then remove the number_format.

1 like

Please or to participate in this conversation.