views:

366

answers:

2

Hi, 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

+3  A: 

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

gbn
+3  A: 

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.

Jon Skeet