which datatype can store monetary values
Answers
Answered by
4
Float datatype .......
Answered by
2
When handling money in MySQL, use DECIMAL(13,2) if you know the precision of your money values or use DOUBLE if you just want a quick good-enough approximate value.
If you want to be compliant with Generally Accepted Accounting Principles (GAAP), then you should use DECIMAL(13,4), a practice that I have personally adopted since the first publication of this article.
As shown in the details section, when summing a column of money values, compute the sum of the series and then round the final result to two decimal places. If you round each value before adding then that can introduce rounding errors that can be difficult to track down.
The Details
On some database management systems (DBMS) there is a data type specially set aside for handling money. However, MySQL doesn’t have one so the choice of best representation is left to the programmer.
Since about 1999, using MySQL 3, I have generally used the DOUBLE data type to represent money values as it stores decimals at reasonably high precision. The values stored are approximations, but the number of decimals treated accurately is enough for normal money values. The ROUND function is helpful when doing aggregation queries, such as:
1 2 3 4 SELECT ROUND(SUM(amount), 2) AS total_amount FROM orders WHERE created_at > '2012-01-01'
Notice that the summation is computed before the final result is rounded to two decimal places. This reduces rounding errors that can appear in large datasets.
However, since MySQL 5 there are some better data types for storing exact money values. From the MySQL manual:
The DECIMAL and NUMERIC types store exact numeric data values. These types are used when it is important to preserve exact precision, for example with monetary data. In MySQL, NUMERIC is implemented as DECIMAL, so the following remarks about DECIMAL apply equally to NUMERIC.
The DECIMAL data type requires you to specify the number of digits before the decimal point and the number of digits after the decimal point.
So if your application needs to handle money values up to a trillion dollars (or euros or pounds), then this should work:
1 DECIMAL(13, 2)
Or, if you need to comply with GAAP then use:
1 DECIMAL(13, 4)
However, considering the rate that the central banks are printing money these days, we might all soon need to be processing larger values for currency.
I hope this helps.
.
.
.
.
.
.
.
.
.
.
.
for more follow me and mark brainliast
If you want to be compliant with Generally Accepted Accounting Principles (GAAP), then you should use DECIMAL(13,4), a practice that I have personally adopted since the first publication of this article.
As shown in the details section, when summing a column of money values, compute the sum of the series and then round the final result to two decimal places. If you round each value before adding then that can introduce rounding errors that can be difficult to track down.
The Details
On some database management systems (DBMS) there is a data type specially set aside for handling money. However, MySQL doesn’t have one so the choice of best representation is left to the programmer.
Since about 1999, using MySQL 3, I have generally used the DOUBLE data type to represent money values as it stores decimals at reasonably high precision. The values stored are approximations, but the number of decimals treated accurately is enough for normal money values. The ROUND function is helpful when doing aggregation queries, such as:
1 2 3 4 SELECT ROUND(SUM(amount), 2) AS total_amount FROM orders WHERE created_at > '2012-01-01'
Notice that the summation is computed before the final result is rounded to two decimal places. This reduces rounding errors that can appear in large datasets.
However, since MySQL 5 there are some better data types for storing exact money values. From the MySQL manual:
The DECIMAL and NUMERIC types store exact numeric data values. These types are used when it is important to preserve exact precision, for example with monetary data. In MySQL, NUMERIC is implemented as DECIMAL, so the following remarks about DECIMAL apply equally to NUMERIC.
The DECIMAL data type requires you to specify the number of digits before the decimal point and the number of digits after the decimal point.
So if your application needs to handle money values up to a trillion dollars (or euros or pounds), then this should work:
1 DECIMAL(13, 2)
Or, if you need to comply with GAAP then use:
1 DECIMAL(13, 4)
However, considering the rate that the central banks are printing money these days, we might all soon need to be processing larger values for currency.
I hope this helps.
.
.
.
.
.
.
.
.
.
.
.
for more follow me and mark brainliast
Similar questions