Numeric Conversions: MySQL
MySQL implements the following numeric conversion functions:
FORMAT(
number
,
scale
)
Provides general-purpose numeric conversions to text. The
scale
is the number of decimal places that you wish to appear in the result.CONV(
number
,
from_base
,
to_base
)
Converts from one base to another. The
number
may be either an integer or a string, and the base may range from 2 through 36.BIN(
number
)
Returns the binary representation of a base-10
number
.OCT(
number
)
Returns the octal representation of a base-10
number
.HEX(
number
)
Returns the hexadecimal representation of a base-10
number
.
For example:
SELECT CONV('AF',16,10), HEX(175), FORMAT(123456.789,2);
175 AF 123,456.79
Use CAST to convert a string to a number.
Get SQL Pocket Guide, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.