Save float values in SQL Server

10,470

Solution 1

You're not actually trying to save 123.66, because you can't represent 123.66 exactly as a float or double. The database is saving the data more accurately than you're used to, that's all.

If you want to save decimal numbers accurately, use the decimal type.

See my articles on floating binary point and floating decimal point types for more info.

Solution 2

This is not a database issue, but a general problem with floating numbers

Share:
10,470
Ashian
Author by

Ashian

Updated on June 12, 2022

Comments

  • Ashian
    Ashian almost 2 years

    I have a simple web app , and want to save some numbers of Float or Double format in SQL server.

    but there is a problem , when I try to save 123.66 , In Table I see 123.6600003662109 stored.

    How nd why my float number changed when save on DB? how can I fix this error?

    Thanks

  • jwpfox
    jwpfox over 7 years
    Please edit your answer to fix the code formatting. Have a read of the guide on how to do this.