How to simplify fractions in C#?

前端 未结 5 2360
暗喜
暗喜 2020-12-11 17:55

I\'m looking for a library or existing code to simplify fractions.

Does anyone have anything at hand or any links?

P.S. I already understand the process but r

5条回答
  •  独厮守ぢ
    2020-12-11 18:33

    You can use Microsoft.FSharp.Math.BigRational, which is in the free F# Power Pack library. Although it depends on F# (which is gratis and included in VS2010), it can be used from C#.

    BigRational reduced = BigRational.FromInt(4)/BigRational.FromInt(6);
    Console.WriteLine(reduced);
        2/3
    Console.WriteLine(reduced.Numerator);
        2
    Console.WriteLine(reduced.Denominator);
        3
    

提交回复
热议问题