Forum Moderators: open
How can I solve that enigma?
NOTE: This function is being applied to a time data type column. It represents the length of time performed by an employee per day, which will be multiplied by a decimal salary rate per hour in another column to find a daily wage of the employee on the fly in a next column.
Kind regards,
D.B
But When I used the expression you just used to reply to the topic, using DECIMAL(3,2) just gave me a value in some of my columns 9.99 (this was the daily work time). But using yours, just gave me a value such 10.00(this is more reasonable work time) which is what I was expecting.
So how can I understand this?
Thanks
M is the total number of digits (the precision) and D is the number of digits after the decimal point (the scale). The decimal point and (for negative numbers) the "-" sign are not counted in M. If D is 0, values have no decimal point or fractional part. The maximum number of digits (M) for DECIMAL is 65. The maximum number of supported decimals (D) is 30. If D is omitted, the default is 0. If M is omitted, the default is 10. M is the total number of digits (the precision) and D is the number of digits after the decimal point (the scale). The decimal point and (for negative numbers) the “-” sign are not counted in M. If D is 0, values have no decimal point or fractional part. The maximum number of digits (M) for DECIMAL is 65. The maximum number of supported decimals (D) is 30. If D is omitted, the default is 0. If M is omitted, the default is 10. UNSIGNED, if specified, disallows negative values.Resource:
[dev.mysql.com...]
So if you wanted to be able to hold a maximum value of 1,234,567.89 you would specify DECIMAL(9,2). The reason I increased your value to 5,2 was so that you could hold more than 9 hours in your calculated daily hours. Now you can hold 999.99 hours. Granted, we don't have that many hours in a day, but it certainly won't hurt to leave it there in case you copy/paste your code for a weekly wage calculation or something and forget to bump up the DECIMAL precision. So, if it is only going to be a daily calculation, you could use 4,2 instead.