Monday October 5th

Sunday October 4th

Friday October 2nd

3 Kicks

A Money Type for the CLR

A convenient, high-performance money structure for the CLR which handles arithmetic operations, currency types, formatting, and careful distribution and rounding without loss. Also, a look at the various approaches out there for creating a Money type on the CLR.


Main problem with this article is summed up in the extract below:

"In this type, I kept the integral value storage, but opted to represent the fraction as a completely separate Int32, which is scaled by 10^9 (the largest power of 10 which fits into an Int32). [...] Another alternative was to represent the money value with a System.Decimal. The problem with this approach is that System.Decimal is a binary floating-point type, and binary floating-point types give us all sorts of headaches when computing with them and not treating the round-off or computational error accumulation with extreme care."

Um... except System.Decimal *isn't* a floating-point type, it's a scaled integer; from MSDN:

"The binary representation of a Decimal value consists of a 1-bit sign, a 96-bit integer number, and a scaling factor used to divide the 96-bit integer and specify what portion of it is a decimal fraction. The scaling factor is implicitly the number 10, raised to an exponent ranging from 0 to 28."

gregbeech -

You need to read more carefully... it _is_ a floating point type. From the same MSDN page:

"A decimal number is a floating-point value that consists of a sign, a numeric value where each digit in the value ranges from 0 to 9, and a scaling factor that indicates the position of a floating decimal point that separates the integral and fractional parts of the numeric value. "

Commenting on Stories is limited for now and will open up to those recommended by the community. Learn how
Loading DotNetKicks...
brought to you by the Kicks Network