Convert from VARCHAR to NUMBER - MySQL

Cast from VARCHAR to NUMBER - MySQL:

Data import

Create table yamicode with the following entries:

CREATE TABLE IF NOT EXISTS `yamicode` (
  `string_number` varchar(250) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

INSERT INTO `yamicode` (`string_number`) VALUES
('5.5'),
('105.6'),
('105'),
('60600'),
('45.456789'),
('NaN');

Convert from VARCHAR to DECIMAL - MYSQL

SELECT CAST(`string_number` as DECIMAL(65,2)) as result FROM `yamicode` WHERE 1

The operation returns the following documents:

result
5.50
105.60
105.00
60600.00
45.46
0.00

the function DECIMAL takes two parameters M and D, they specify the maximum number of digits (the precision) and the number of digits following the decimal point (the scale).

Convert from VARCHAR to INTEGER - MYSQL

SELECT CAST(`string_number` as SIGNED) as result FROM `yamicode` WHERE 1

The operation returns the following documents:

result
5
105
105
60600
45
0