Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Losing precision when converting a float datatype to varchar

HiIsMeHiIsMe Member Posts: 1
How can I convert my float type to a varchar datatype.
When the number has more than 6 decimal places SQL rounds the decimal portion of the number. I haven't found a way to not lossin the precision.

IF I convert the float value to a numeric value, sometimes it converts it like this: 123.985899999
and it should be 123.9859.

Does anyone know something about this?

Thanks

Comments

  • Sinjith_shrSinjith_shr Member Posts: 6
    : Hi Friend
    Numeric datatype will take ur full data if u r giving a big preicision and scale. If it so it won't round the value

    please try this query, then u will come to know

    Select cast(123.985899999 as numeric(15,12))
    it will give the correct answer


    How can I convert my float type to a varchar datatype.
    : When the number has more than 6 decimal places SQL rounds the decimal portion of the number. I haven't found a way to not lossin the precision.
    :
    : IF I convert the float value to a numeric value, sometimes it converts it like this: 123.985899999
    : and it should be 123.9859.
    :
    : Does anyone know something about this?
    :
    : Thanks
    :

Sign In or Register to comment.