Home > Blockchain >  Set number limit to 2 decimals
Set number limit to 2 decimals

Time:10-25

I am having a problem creating a function for SQL server query in php or changing how the value output I get in index page where the result would be something like = 25.879999999999999 when I want it as 25.87

when ap.idproduct = 1 then cast(tr.PreviousBalance as float)/100 
else cast(tr.FinalBalance as float)/100 end as balance_before,

need float limited to 2 decimals or a function ( please explain how it is used as I kinda new to PHP)

CodePudding user response:

FIX :

ROUND(cast(tr.PreviousBalance /100 as float), 4)

Wrapping cast in round

CodePudding user response:

You can use number_format():

if($ap.idproduct == 1){
   $result = $tr.PreviousBalance/100
}else{
    $result = $tr.FinalBalance/100
}
return number_format((float)$result, 2, '.', '');
  • Related