devxlogo

Using CAST for Explicit Conversion in MySQL

Using CAST for Explicit Conversion in MySQL

MySQL allows you to explicitly convert a number to a string with the help of CAST function. The example below illustrates how to use it.

SELECT 55.5 AS NUMBER, CAST(55.5 AS CHAR) AS CAST_NUMBER;

Output:

+-----------------------+| NUMBER  | CAST_NUMBER |+-----------------------+|    55.5 | 55.5        |+-----------------------+

You can observe that the first column is a number whereas the second column has a string value that is also left aligned.

There is also the CONCAT function which implicitly converts NUMBER to STRING when used.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist