I\'d like to be able to get the bits from a System.Decimal
value and then convert that to the string representation of the value, much like Decimal.ToStri
Since you cannot use ToString()
, you might want to check out how the mono developers implemented this:
The entry point is NumberToString(string, decimal, IFormatProvider).
The interesting part is InitDecHexDigits(uint, ulong), which gets called like this
InitDecHexDigits ((uint)bits [2], ((ulong)bits [1] << 32) | (uint)bits [0]);
and does the "bit juggling and shifting" thing to convert the three integers into binary coded decimals (_val1 to _val4), which can then be (trivially) converted into a string.
(Don't get confused by the fact that they call it "hex representation". It's binary coded decimal digits.)