Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert decimal number to INT SQL

I want to convert the decimal number 3562.45 to 356245, either as an int or a varchar. I am using cast(3562.45 as int), but it only returns 3562. How do I do it?

like image 347
Zaeron25 Avatar asked Mar 30 '16 22:03

Zaeron25


3 Answers

How about the obvious:

CAST(3562.45*100 as INTEGER)
like image 155
Mike Dinescu Avatar answered Sep 30 '22 13:09

Mike Dinescu


Or you can replace the decimal point.

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

This way, it doesn't matter how many decimal places you have.

like image 34
Dan Bracuk Avatar answered Sep 30 '22 15:09

Dan Bracuk


This works for me

SELECT FLOOR(55.5999)
like image 29
Varun Avatar answered Sep 30 '22 13:09

Varun