开发者

SqlCeServer: Float stores incorrectly

In my debugger (VS2010), I can verify that I am sending the correct values to my SqlCeServer 3.5 database using an SqlCeCommand.

Looking at the data afterwards, I noticed that some of my float values a开发者_开发问答re skewed.

  • When I enter 0.006, the database will store 0.0060000000521540642

  • When I enter 0.012, the database will store 0.0120000001043081

  • When I enter 0.011, the database will store 0.0109999999403954

Other float values (1.125, 0.875, 0.75) store just fine.

Is there something special I have to do to ensure my float values store correctly?


Don't use float: it's approximate

Use fixed precision: decimal/numeric


From msdn:

"not all values in the data type range can be represented exactly. "

Looks like you have found some of them!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜