This question already has answers here:
PHP rand() vs. random_int()
(6 answers)
Closed 2 years ago.
I am new to laravel .
I want to know what does rand(1,6) means ?
if (rand(1,6) < 5)
{ //some code
}
Could someone please brief it in detail .
This is a basic php function - https://www.php.net/manual/en/function.rand.php
It gets a pseudo-random integer from 1 to 6, and if the random number is less than 5 the code is run.
It's a php function to generate random numbers between the two given parameters
Here the chance will be 2/3 that the if statement gets executed
https://www.php.net/manual/de/function.rand.php
EDIT:
The chance is 2/3 because the function will generate a random number between 1 and 6 -> 1, 2, 3, 4, 5 or 6 which means that there are 4 numbers smaller than 5. Thus our chance is 4 numbers of 6 numbers (=> 4/6) which is equal to 2/3
Related
This question already has answers here:
Rounding up to the second decimal place [duplicate]
(2 answers)
PHP: Round a number upto 2 decimal places and if the number is a whole number then add trailing zeros
(4 answers)
Closed 2 years ago.
Thank you if you help me to solve this.
I need this round up with 2 decimal
<? echo round(ceil((0.55*100))/100,2); // output 0.56 ?>
I want this
0.050 -> 0.05
0.051 -> 0.06
0.055 -> 0.06
0.059 -> 0.06
0.060 -> 0.06
Thank you!
This question already has answers here:
Show a number to two decimal places
(25 answers)
Closed 2 years ago.
i need to round off up-to 2 decimal,currently i getting 12% but the actual discount is 11.76
my code as follow
$perc=0;
if($value->IsOfferItem){
$perc=round(100-(($value->SellingPrice/$value->ActualPrice)*100));
}
Here's an example
$table->decimal('amount', 5, 2);
In above example first parameter is the field name. Second, parameter is the total length. Third, parameter is the float value.
the table field, for example in mysql must contain decimal (10.2), example:
amount dcecimal(10,2) not null
The 2 indicates decimal places.
The 10 indicates the maximum numerical quantity before the comma.
This question already has answers here:
How to use MySQL DECIMAL?
(4 answers)
Closed 6 years ago.
so in my database i store my users earnings but they will not go any higher than 0.99999 i try and add 0.000001 to it but will not go over to 1.00000 for some reason the column is decimal(5,5)
here is my update
$fdfsdfdsfsdf = mysql_query("UPDATE users SET available_earning=available_earning+0.00012 WHERE id = '".$owner2."'")
or die(mysql_error());
what am i doing wrong? Sorry about my variable names and yes i will be updating it all to pdo soon
You've defined the column as DECIMAL (5, 5). That means 5 significant digits, with all five to the right of the decimal point. The term "significant digits" means all digits on both sides of the decimal point.
Short version: you need to redefine the column as DECIMAL (x, 5) where x > 5 if you want to store values >= 1.
This question already has answers here:
How to fastest count the number of set bits in php?
(6 answers)
Closed 8 years ago.
If i have 2 binary number representation: 127 and 128. How can i calculate that 127 have 7 bits "ON" and 128 have only 1 bit "ON"?
I did it like the following, but i think there's probably a better way (with math):
strlen(str_replace('0','',decbin(127))); // 7
strlen(str_replace('0','',decbin(128))); // 1
It looks like what you want is a population count. The Wikipedia reference has some code, and for problems like this I always check Bit Twiddling Hacks which is a great reference.
There are asm instructions for this on some machines, and both gcc and MSVC have compiler builtins.
For other languages, see: Population Count on RosettaCode
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Round up to the nearest 50,000 in PHP
I have this, 52.52 and I want it to become 52.5. How would I do that in PHP? I tried round() but did not work. Thanks.
round($num, 1);
should round $num to the nearest tenth (the second argument specifies the precision, or the number of digits after the decimal it should round to)
Try
$x = number_format('52.52', 1)
Documentation is here