Is this se开发者_运维百科t somehow in a variable?
Is it possible to store decimal values in INT
fields or does it have to be FLOAT
?
Comma or point as a separator? Or does it even matter?
Thanks
Commas aren't stored in the table...they're represented that way in whatever you're viewing the data with.
For decimal numbers, no you cannot use INT
, it only accepts whole numbers, you likely want DECIMAL
for this (So you don't get the odd 0.3999999999999999999999999999999 that can't be stored quite right in the float).
The separator is not stored in the database. You can apply separator using the FORMAT function.
mysql> SELECT FORMAT(12332.123456, 4);
-> '12,332.1235'
mysql> SELECT FORMAT(12332.1,4);
-> '12,332.1000'
mysql> SELECT FORMAT(12332.2,0);
-> '12,332'
http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html
An INT field doesn't store precision. If you want to store fractions/decimals, then you need to choose a data type that will support them. The MySQL documentation is pretty good about what each data type provides you. I frequently go back to the MySQL documentation when I need a refresher on data types.
精彩评论