In MySQL, we often need to convert between different numeric types. MySQL provides some built-in functions that can help us convert numeric types. This article will introduce some commonly used MySQL number type conversion functions and provide corresponding source code examples.
- CAST function
The CAST function is used to convert an expression to a specified data type. It can be used to convert a number to a different number type, such as converting an integer to a floating point number, or a floating point number to an integer.
Sample code:
SELECT CAST(10 AS FLOAT); -- 将整数转换为浮点数
SELECT CAST(3.14 AS INT); -- 将浮点数转换为整数
- CON