Is there a way to get the “significant figures” of a decimal?

后端 未结 3 373
渐次进展
渐次进展 2020-12-31 05:10

Update

OK, after some investigation, and thanks in big part to the helpful answers provided by Jon and Hans, this is what I was able to put together. So far I thin

3条回答
  •  心在旅途
    2020-12-31 05:50

    Yes, unlike floating point types, System.Decimal keeps track of the number of digits in the literal. This is a feature of decimal.Parse(), whether executed by your code yourself or by the compiler when it parses a literal in your program. You can recover this information, check out the code in my answer in this thread.

    Recovering the number of significant digits after you do math on the value strikes me as a long shot. No idea if the operators preserve them, please let us know what you find out.

提交回复
热议问题