Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What column type should I use to store values between 0 and 1 (say up to 5 decimal places) in MySQL?

Tags:

mysql

It is most important that it be accurate, but also it should take the least disk space possible.

like image 276
EdanB Avatar asked Jan 04 '10 09:01

EdanB


People also ask

Which data type should be used to store a value with a decimal portion?

Note: The decimal data type is suitable for storing currency data where the required range of values or number of digits to the right of the decimal point exceeds the capacities of the money data type.

Which type of MySQL function accepts only numeric values?

Fixed-Point Types Fixed-Point data types are used to preserve exact precision, for example with currency data. In MySQL DECIMAL and NUMERIC types store exact numeric data values.

How can store floating point number in MySQL?

MySQL permits a nonstandard syntax: FLOAT( M , D ) or REAL( M , D ) or DOUBLE PRECISION( M , D ) . Here, ( M , D ) means than values can be stored with up to M digits in total, of which D digits may be after the decimal point. For example, a column defined as FLOAT(7,4) is displayed as -999.9999 .


1 Answers

You would need a DECIMAL(6,5) to store a number from 0 to 1 with 5 decimal places.

The declaration syntax for a DECIMAL column is DECIMAL(M,D). The ranges of values for the arguments in MySQL 5.1 are as follows:

  • M is the maximum number of digits (the precision). It has a range of 1 to 65.

  • D is the number of digits to the right of the decimal point (the scale). It has a range of 0 to 30 and must be no larger than M.

like image 180
Daniel Vassallo Avatar answered Nov 15 '22 06:11

Daniel Vassallo