I am not able to insert a field into Mysql. Input is passed from HTML form as string. I think that problem is due to type mismatch. DB type is double
And i can't able to convert it into Double or float. using floatval() or Doubleval().
usually the input is like 8 i want it convert it as 8.0
You can insert 8
perfectly safely into a decimal or float. It doesn't have to be 8.0
at all.
If you are having trouble inserting the value in, it isn't the data type on your database, but another issue.
If you post further detail, we will look into more :)
Edit: Here is some input data into int
, decimal
and float
types:
mysql> create table numberTest(inty int(2), decy decimal(3,2), floaty float(3,2));
Query OK, 0 rows affected (0.01 sec)
mysql> select * from numberTest;
Empty set (0.00 sec)
mysql> insert into numberTest values(7,7,7);
Query OK, 1 row affected (0.00 sec)
mysql> insert into numberTest values(7.2,7.2,7.2);
Query OK, 1 row affected (0.00 sec)
mysql> select * from numberTest;
+------+------+--------+
| inty | decy | floaty |
+------+------+--------+
| 7 | 7.00 | 7.00 |
| 7 | 7.20 | 7.20 |
+------+------+--------+
2 rows in set (0.01 sec)
If you can't insert your values, show your insert commands in PHP, it isn't the data type. You are barking up the wrong tree with this question.
$number = 8;
echo number_format($number, 1, '.', ' '); //8.0
echo number_format($number, 2, '.', ' '); //8.00