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.
Related
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 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:
Best data type to store money values in MySQL
(13 answers)
Closed 8 years ago.
Is this the right way to show the float number within the MySQL Database?
if ($a == "balance") {
$querys= "SELECT balance FROM users WHERE Username='$user'";
$results= mysql_query($querys);
$rows = mysql_fetch_row($results);
$bfloat = (float)$rows['balance'];
echo $bfloat;
}
in the MySQL database the column name balanace is float and as example at the current user the value is 1.73. So its answer would be 1.73
Bad news. The answer should be approximately 1.73. For that in typed languages separate decimal types are used (java BigDecimal). See Decimal type in php for the same in PHP.
Floating point is approximates our decimal representation, it would need infinite number of digits in the binary system (base 2). Just as 2/7 in base 10, whereas it is 0.2 in base 7.
Also it is better tp accustom oneself to use prepared statements http://xkcd.com/327/
This question already has answers here:
Returning query results in predefined order
(11 answers)
Closed 9 years ago.
I have a user input box, querying a column of numbers in my SQL database, which, for example are:
2.0
3.0
4.0
5.0
6.0
7.0
8.0
The user will have to type in a number, and then populate a particular order of the list of numbers to respond to the input from the user.
So if the user input was 4.0, then i want the database query to display
4.0,3.0,5.0,2.0,6.0,7.0,8.0.
To break the results down, I want the result pattern to display the database results with the closest number to the input(4.0),then the next result, if available, to be lower by 1 degree(3.0), then higher by 1 degree(5.0),then lower by two degrees (2.0), and higher by two degrees(6.0). The 7.0 and 8.0 numbers are displayed numerically because there is no lows to match them.
How can I setup a query for this pattern of results?
SELECT *
FROM mytable
ORDER BY
ABS(value - 4.0), SIGN(value - 4.0)
See SQLFiddle