Skip to main content
adicionou 262 caracteres ao conteúdo
Fonte Link
Marllon Nasser
  • 3,9mil
  • 15
  • 29

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

É isso?

<?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

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

É isso?

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

Output:

25.4

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

É isso?

<?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
Fonte Link
Marllon Nasser
  • 3,9mil
  • 15
  • 29

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

É isso?

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

Output:

25.4