Home > OS >  Convert to int in mySql
Convert to int in mySql

Time:06-04

I'm trying to convert a number to int without any success @ MySQL:

select cast (int, 12.345); 
select cast 12.345 as int; 
select convert (12.345, int); 

and more variations of the above 2 functions - failing at all. Thanks in advance! Best Regards, Eyal :)

CodePudding user response:

select cast(replace('12.345', '.','') as integer)

CodePudding user response:

You can transform a float into an integer using CAST with the UNSIGNED type:

SELECT CAST(12.345 AS UNSIGNED);

Try it here.

  • Related