Decimal stores precision from parsed string in C#? What are the implications?

后端 未结 3 2001
萌比男神i
萌比男神i 2021-02-07 11:10

During a conversation on IRC, someone pointed out the following:

decimal.Parse(\"1.0000\").ToString() // 1.0000
decimal.Parse(\"1.00\").ToString() // 1.00
         


        
3条回答
  •  天涯浪人
    2021-02-07 11:29

    A decimal consists of a 96-bit integer and a scaling factor (number of digits after the decimal point), which ranges from 0 to 28. Thus:

    • 1.000 becomes 1000 with scaling factor 3.

提交回复
热议问题