Reputation: 33
Using MySQL 5.0.27
This query: SELECT CAST('543.21' AS DECIMAL(100,2))
returns 543.21
So does this one: SELECT CAST('543.21' AS DECIMAL(2,2))
In fact, I am having trouble figuring out what effect the parameter has. I am using it to aggregate numeric values in a varchar column (for legacy reasons!!) and round off to 2 decimal places.
Should I just pick a high number?
Upvotes: 3
Views: 2346
Reputation: 62395
It describes how many total digits a field (or variable) will be able to store. DECIMAL(100,2) - 100 total digits, 98 before, 2 after a decimal separator DECIMAL(2,2) 2 total digits, 0 before, 2 after a decimal separator
Explained here: http://dev.mysql.com/doc/refman/5.1/en/numeric-types.html
[added]
For rounding just use ROUND() function.
Upvotes: 5