From the course: MySQL Essential Training (2019)

Value functions

- [Instructor] MySQL provides several functions for constraining the values of numbers. For example, select ABS will give us the absolute value of a number. And if I say absolute value of minus 47, I get 47. Or if I say the absolute value of minus 47.73, a real number, now I get minus 47.73. The absolute value function, provides the absolute value of a signed number and the result will always be positive. The ceiling function, returns the lowest integer value that is not lower than the operand. For example, if I say ceiling of 12.2, my result is 13. Because 12 would be lower than the operand and so 13 is the lowest value that is not lower than the operand. And ceil without the ing, is an alias for ceiling. The floor function is the inverse of ceiling. Floor returns the highest integer, that is not higher than the operand. In this case, 12, 13 would be higher than 12.9, but 12 is not, so the result is 12. The round function, returns a standardized rounded number. So if I say round of 17.5, I'm going to get 18. And if I say round of 17.4, I'm going to get 17. So round, returns a real number, rounded to the nearest integer. Truncate is a bit different. The truncate function will truncate a number to a given number of decimal places. So truncate 42.973, to one decimal place, will give you 42.9. This is not rounded you'll notice. It did not round it up to 43. And so if I give it a two here, it'll give us 42.97. And a negative number, will truncate to the left of the decimal. So if I say 99942.973 minus two, I get just 99900. So it truncates to the left of the decimal and it fills the remaining digits with zero. These functions are provided to manipulate the values of numbers in simple ways.

Contents