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

后端 未结 3 374
渐次进展
渐次进展 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

    You can use Decimal.GetBits to get the raw data, and work it out from that.

    Unfortunately I don't have time to write sample code at the moment - and you'll probably want to use BigInteger for some of the manipulation, if you're using .NET 4 - but hopefully this will get you going. Just working out the precision and then calling Math.Round on the original result may well be a good start.

提交回复
热议问题