Format PHP values

0

I'm trying to format a value that exits from the rand() function except that it is not the normal way. I have rand() :

<?php
$valor = rand(3000,7000);

echo number_format($valor, 2);
?>
  

Output: 5000.00

I need the output to be 50.00 and not 5000.00.

I had a code that rand() would go with the "." (dot), being more or less so

<?php
rand(30.00, 70.00)
?>

But it seemed that he made the draw with the first 2 values, from 30 to 70 and also need to get the cents, that is, it could be a draw that goes out for example 41.32

    
asked by anonymous 29.12.2015 / 04:05

1 answer

0

rand($min*10, $max*10)/10

Is that it?

<?php
echo rand(20*10,30*10)/10
?>

Output:

25.4

Edit:

<?php
function randomWithDecimal($min, $max, $decimal = 0) {
  $scale = pow(10, $decimal);
  return mt_rand($min * $scale, $max * $scale) / $scale;
}
echo randomWithDecimal(30, 70, 2);
?>

Output:

44.37
    
29.12.2015 / 04:13