mrblah
mrblah

Reputation: 103717

does money map to float well?

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

Upvotes: 2

Views: 1543

Answers (4)

JonH
JonH

Reputation: 33183

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.

Upvotes: 2

Guffa
Guffa

Reputation: 700910

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.

Upvotes: 1

Reed Copsey
Reed Copsey

Reputation: 564931

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.

Upvotes: 1

Justin Niessner
Justin Niessner

Reputation: 245509

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.

Upvotes: 12

Related Questions