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.
Related
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
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 strip trailing zeros in PHP
(15 answers)
Show a number to two decimal places
(25 answers)
Closed 7 years ago.
This questions is kinda confusing, but here I am telling you the exact problem I have.
In database I have a column with datatype double(10,6), means the value can have upto 6 decimals depending on each user.
Some user have a value 5.22 say in this column.
Now when I echo this value in php, I want it to show 5.22 or 7.256 not 5.220000 or 7.256000.
I hope its clear.
Thanks.
This question already has answers here:
PHP float/double stored as MySQL DECIMAL
(2 answers)
Closed 8 years ago.
I have a table with a DECIMAL(10,6) column. I have a string representation of a float (e.g. 35.3123122). I am using php to insert the value. I used floatval($string) to insert and it did not work. I also tried to insert the string itself with no success. Do I need to format the float value exactly to match the 10,6 criteria. If so, How can I do this?
Thanks
Not sure if this is your problem, but the value of "35.3123122" has 7 digits after the decimal point. DECIMAL(10,6) is 10 digits in total with a maximum of 6 digits past the decimal point.
This question already has answers here:
Show a number to two decimal places
(25 answers)
Closed 8 years ago.
Having the following decimal numbers:
47.44
180.11
340
12.39
25
I was wondering, how can I add a default .00 to those numbers, that have no decimals?
You can use number_format() like that:
number_format($number, 2);
It'll always return number with two decimals. Also it'll separate thousands with ',' (if you don't want that, add '' as fourth parameter).