BigInteger division in C#

后端 未结 7 1548
礼貌的吻别
礼貌的吻别 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:49

    Sound like a job for Fixed Point (rather than floating point).

    Simply pre-shift the numerator by the number of fractional bits you need, like this:

    BigInteger quotient = (x << 10) / y;
    

    That would give you 10 bits after the dot (approximately 3 decimal digits).

提交回复
热议问题