How can I print decimal numbers like
0.05
0.10
0.15
0.20
0.25
0.30
0.35
0.40
0.50
.
.
.
1.25
Tried with below code but it does not work
<?php
$start = 1;
$end = 3;
$place = 0.5;
$step = 0.05 / pow(10, $place);
for($i = $start; $i <= $end; $i = round($i + $step, $place))
{
echo $i . "
";
}
?>
You can build a range of the values needed.
Here I create from 0 -> 5 with 0.05 increment.
$range = range(0, 5, 0.05);
foreach($range as $val){
echo number_format($val, 2) . "
";
}
If the decimals are not important a simpler way to output would be with implode.
echo implode("
", $range);
Taking the problem literally, here is a way to solve it.
$start = 0.05;
$increment = 0.05;
for ($i=0; $i < 25; $i++) {
echo number_format($start, 2, '.', '').'<br>';
$start += $increment;
}