Best data type for storing currency values in a MySQL database

1.1K    Asked by AmeliaArnold in Big Data Hadoop , Asked on Jun 24, 2021

What is the best SQL data type for currency values? I'm using MySQL but would prefer a database independent type.


Answered by Ema Harada

You must use fixed-point numeric data type for storing the money values in MYSQL like this:

decimal(15,2)

Here, 15 is the precision (i.e. total length of value including decimal places) and 2 is the number of digits after the decimal point.

Note: mysql money data type needs an exact representation. So, never use data-type that is only approximate like float. 


Your Answer

Interviews

Parent Categories