Is it possible to call js library in .net core Web api

273 Views Asked by At

We are using the Math.js library for evaluating the string expressions in Angular. Now we need to implement the same in C# for the same expression. Is there any equivalent library to Math.Js in C# or can we call Math.js library in C#?

below is an example string expression which can be evaluated using math js

a = 2, b = 3, c = 3, d = 5, e = 7
ceil(a)*b+(ceil(c)+1)*(d+e)
1

There are 1 best solutions below

3
ZarX On

The equivalent of Math.Js in C# would be the Math class that is a part of the System.Runtime.Extension.dll assembly. That provides constants and static methods for trigonometric, logarithmic, and other common mathematical functions.

Down below is a conversion to Math class based on the example in your question.

    decimal a = 2;
    decimal b = 3;
    decimal c = 3;
    decimal d = 5;
    decimal e = 7;
    decimal result = Math.Ceiling(a) * b + (Math.Ceiling(c) + 1) * (d + e);

Working example: https://dotnetfiddle.net/GOsGsi