Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best datatype for currencies in MySQL?

I want to store values in a bunch of currencies and I'm not too keen on the imprecise nature of floats. Being able to do math on them directly in queries is also a requirement.

Is Decimal the way to go here?

like image 690
grapefrukt Avatar asked Oct 29 '08 21:10

grapefrukt


People also ask

Is there a currency data type in MySQL?

We can store the money values in MySQL in decimal(value1,value2). Here, value1 is the total range including value2. The value2 specifies the number of digits after the decimal point.

Which data type is best for currency amounts?

The best datatype to use for currency in C# is decimal. The decimal type is a 128-bit data type suitable for financial and monetary calculations. The decimal type can represent values ranging from 1.0 * 10^-28 to approximately 7.9 * 10^28 with 28-29 significant digits.

What data type should currency be in SQL?

It's simply a decimal type with less precision than a decimal .

What should be the datatype of price in MySQL?

The best type for price column should be DECIMAL. The type DECIMAL stores the value precisely. For Example - DECIMAL(10,2) can be used to store price value. It means the total digit will be 10 and two digits will be after decimal point.


1 Answers

Decimal is the best way to go.

You can still do math within the queries.

like image 130
bobwienholt Avatar answered Oct 15 '22 12:10

bobwienholt