decimal places correction

  • Hi All,

    I want my numbers to be converted from a column which is of nvarchar(100) datatype to decimal(18,2).
    How can I correct it?

    select CONVERT(DECIMAL(18,2),'129399389')

    --I' am getting output as
    129399389.00

    But I am expecting output as
    1293993.89

    Thanks,

    Sam

  • You need to CONVERT and then divide by 100. An Integer, as a decimal, doesn't change its value.

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • Thanks Thom.

  • vsamantha35 - Monday, November 27, 2017 6:00 AM

    Hi All,

    I want my numbers to be converted from a column which is of nvarchar(100) datatype to decimal(18,2).
    How can I correct it?

    select CONVERT(DECIMAL(18,2),'129399389')

    --I' am getting output as
    129399389.00

    But I am expecting output as
    1293993.89

    Thanks,

    Sam

    There is nothing to correct. Datatype conversions do not perform arithmetical operations (though values may change due to rounding).


  • You might also want to consider what happens if your nvarchar(100) column contains more than 16 digits.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply