does money map to float well?

2020-07-26 09:24发布

does the sql data type money map to c# float?

4条回答
男人必须洒脱
2楼-- · 2020-07-26 09:33

No.

Money maps to Decimal. If the MONEY column allows null values, it will map to Nullable<Decimal>. For details, see SQL-CLR Type Mapping.

Float is not nearly precise enough for numerical computations dealing with money. You should always do all of your calculations using decimal values.

查看更多
家丑人穷心不美
3楼-- · 2020-07-26 09:35

No, a float has way too low precision to handle monetary values. Seven digits doesn't get you far. Also a floating point type is prone to rounding errors due to how the numbers are represented.

Use the Decimal data type.

查看更多
相关推荐>>
4楼-- · 2020-07-26 09:50

No...it maps to a decimal. If the column allows null, it maps to Nullable<Decimal>.

Mapping CLR Parameter Data

float isn't precise enough to be used for monetary calculations. You'd be losing/gaining money all over the place.

查看更多
劳资没心,怎么记你
5楼-- · 2020-07-26 09:52

I'd use decimal.

The Decimal value type represents decimal numbers ranging from positive 79,228,162,514,264,337,593,543,950,335 to negative 79,228,162,514,264,337,593,543,950,335. The Decimal value type is appropriate for financial calculations requiring large numbers of significant integral and fractional digits and no round-off errors. The Decimal type does not eliminate the need for rounding. Rather, it minimizes errors due to rounding.

查看更多
登录 后发表回答