Conversion issue when assigning smallmoney data type to varchar

  • I have been facing a value truncation issue while storing smallmoney/float type value into varchar type. Seems implicit converison not working the way what expected. For example look at the below lines:

    Declare @V1 Varchar(10)

    Declare @V2 smallmoney

    Set @V2=1.12345

    Set @V1=@V2

    Print @V1

    Output:

    1.12

    While it should be 1.12345

    Please share your views on this.

  • believe that it is because of the following:

    Set @V1=@V2 is doing CAST. And for CAST and smallmoeny data type default is to show 2 decimal digits.

    If you do

    CONVERT (varchar(10),@V@,2)

    You should get 4 decimal digits.

    (2 is for the style of showing it)

    Also, smallmoney can have MAX 4 decimal digits, so you should either using some other type of have: Set @V2=1.1234

    Please check BOL for CAST and CONVERT

  • Thanks a lot.

Viewing 3 posts - 1 through 2 (of 2 total)

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