Hi,
printf("%.2f", $value) ; will print $value with 2 decimal points...
but how can I get this value into a variable?
so for example, if $value was 33.5 it would make $value = 33.50
thanks in advance Ben
try following:
$n = 12.3; echo number_format($n, 2);
wizkid
Wohoo! Thanks wizkid! 😃
From what I understand is that the new value should be whatever printf made the previous value.
try this
<? $value = 235; $value = printf("%.2f", $value);
echo $value; ?>
Hope it helps. Cheers
I tried that but it didnt seem to work, it just returned nothing...
I tried that but it didnt seem to work
sprintf() instead of printf()
and that will return itself as a var value? like $value1 = "3.5621" ; $value2 = sprintf("%.2f", $value1);
Originally posted by benbox and that will return itself as a var value?
¿Que?
if you want to have the altered value a variable, all you have to do is....
$original_val = "6.5"; $altered_val = number_format($original_val, 2);
if you echo the variable, output will be '6.50'