number_format returns a string; you could instead round to two decimal places:
round($num, 2)
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
This might be dumb question, but i need the answer fast, so asking here in the forum.
$num = "39.34343"
echo $num = number_format((float)$num,2, '.', '');
//output $num = "39.34"
When I echo $num always getting string in this case.
So i tried to type cast it with float
echo $num = (float)number_format((float)$num,2, '.', '')
//output $num = 39.54545454545
I need my value to be 2 decimal float
Please or to participate in this conversation.