How To Insert a DECIMAL(a,b) Value Into MYSQL [duplicate] - php

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.

Related

how to round to decimal point in laravel [duplicate]

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.

vaule wont go any higher in mysql [duplicate]

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.

Showing decimal values until its not 0 [duplicate]

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.

If no decimals, add default ones [duplicate]

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).

Insert comma(,) into a value using jQuery [duplicate]

This question already has answers here:
Add comma to numbers every three digits
(14 answers)
How to format numbers? [duplicate]
(17 answers)
Closed 8 years ago.
Hello there i have problem in jQuery. Suppose i have a value like 20000. And i want the value like 20,000 that after two number a comma will be inserted. I can't do it using jQuery. Please anyone help me out.
Since you said you want the comman inserted "after two numbers", I'm going to assume you have the easy case where you know that your input is a 5 digit number and don't want a more generic number formatting solution. In that case you can do something just like:
var num = 20000;
num = num.toString();
num = num.substr(0,2) + ',' + num.substr(2);
// Now num === "20,000"
Note that 20,000 will only read as twenty-thousand in certain locales. It could be read as just twenty in many locales, but 20000 will be read correctly by anyone who understands Arabic numerals.

Categories