Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save float values in SQL Server

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

like image 414
Ashian Avatar asked Jun 17 '09 08:06

Ashian


2 Answers

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.

like image 70
Jon Skeet Avatar answered Oct 22 '22 09:10

Jon Skeet


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

like image 45
gbn Avatar answered Oct 22 '22 08:10

gbn