• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

PHP Random # Generator

Stoltenborg

[H]ard|Gawd
Joined
Oct 18, 2000
Messages
1,394
Not a HW problem btw.


I am just doing some simple php for a website and I want a random number from 6 to 10 to show with 2 decimal places, ie 7.49.

this is the code i have but the decimals just all show .00 (6.00, 7.00, 8.00, etc)


Code:
<?php $number=rand(6.00,10.99);  

echo number_format($number,2);

 ?>
 
That's because rand() returns an integer. For a number between 6.00 and 10.99 inclusive, I'd do this:

$number = 6.0 + (rand(0, 499) / 100.0);
 
That's great news. Good luck with your project!
 
Back
Top