BigInteger division in C#

后端 未结 7 1525
礼貌的吻别
礼貌的吻别 2020-12-09 19:05

I am writing a class which needs accurate division of the BigInteger class in C#.

Example:

BigInteger x = BigInteger.Parse(\"10000000000000000000000         


        
相关标签:
7条回答
  • 2020-12-09 19:56
    //b = 10x bigger as a => fraction should be 0.1
    BigInteger a = BigInteger.Pow(10, 5000);
    BigInteger b = BigInteger.Pow(10, 5001);
    
    //before the division, multiple by a 1000 for a precision of 3, afterwards 
    //divide the result by this.
    var fraction = (double) BigInteger.Divide(a * 1000, b) / 1000;
    
    0 讨论(0)
提交回复
热议问题