How to convert System.Decimal bits to string in C#?

前端 未结 4 1772
天涯浪人
天涯浪人 2021-01-18 20:36

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

4条回答
  •  无人共我
    2021-01-18 20:49

    You can use the Decimal constructor Decimal(Int32[]) to convert your value back:

    Decimal Constructor (Int32[])

    Initializes a new instance of Decimal to a decimal value represented in binary and contained in a specified array.

    Afterwards, you can use ToString if you want. Example:

    decimal d = 1403.45433M;
    int[] nDecimalBits = decimal.GetBits(d);
    
    decimal d2 = new decimal(nDecimalBits);
    string s = d2.ToString();
    

提交回复
热议问题