Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing 0.00001 in MySQL

I have an earn site and I would like the user to earn 0.00001 per click (I know it's under 1p).

What type of column could I use? I have tried int and float but neither works.

like image 632
nick Avatar asked Jun 01 '11 14:06

nick


People also ask

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 .

Is event a keyword in MySQL?

Yes, it is generally best practice to avoid giving your objects names that are keywords (reserved or not).


1 Answers

Use DECIMAL for exact values.

The number 0.00001 has 6 digits. 1 before and 5 after the decimal point. Therefore, it would be represented as DECIMAL(6, 5) (6 digits out of which 5 are after the decimal point). If you would like to have, say, 4 digits before and 5 digits after the decimal point, you'd use DECIMAL(9, 5) (9 in total, out of which 5 are after the decimal point).

Also see:

  • Precision Math
  • Problems with Floating-Point Values
like image 166
rid Avatar answered Nov 01 '22 17:11

rid