I have a result of decimal number
0.666667
and i wold like to fool it or round it to 0.6,
number_format((float)0.66667, 1, '.', '')
but I get 0.7
floor(0.66667)
gives me 0
how can i take this result and floor it to 0.6 or ceil it to 0.7
CodePudding user response:
function floordec($zahl,$decimals=1){
return floor($zahl*pow(10,$decimals))/pow(10,$decimals);
}
echo floordec(0.66667);
CodePudding user response:
You can multiply by 10, floor(), then divide by 10 again.
floor( 0.666667 * 10 ) / 10