Zaeron25
Zaeron25

Reputation: 149

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?

Upvotes: 13

Views: 153889

Answers (4)

Varun
Varun

Reputation: 181

This works for me

SELECT FLOOR(55.5999)

Upvotes: 13

arman1991
arman1991

Reputation: 1166

You can use also the CONVERT function:

SELECT CONVERT(INT, 3562.45 * 100)

Upvotes: 7

Dan Bracuk
Dan Bracuk

Reputation: 20804

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.

Upvotes: 13

Mike Dinescu
Mike Dinescu

Reputation: 55760

How about the obvious:

CAST(3562.45*100 as INTEGER)

Upvotes: 24

Related Questions