Search code examples
sqlsql-servercastingdecimalnumber-formatting

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?


Solution

  • 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.