Normally, advanced math is not something used a lot in an ERP system, and historically NAV and BC haven’t had a comprehensive math library available, but that has changed, check it out:

In this video, Erik explores the math capabilities available in Business Central’s AL language, why they’ve historically been so limited, and how you can extend them by contributing to the open-source System Application.
The Dirty Secret of Math in Business Central
Ever since the birth of Business Central (going back through Dynamics NAV and Navision), the platform has had a very limited set of math functionality. Erik reveals the dirty secret: the only features available in AL are those that Microsoft (or Navision before them) needed to build their own application. If they had no use for cosines, sines, tangents, or similar functions, the functionality simply wasn’t included.
It wasn’t until very recently that AL even got a Random function — because why would you need randomness in an ERP system?
The basics are covered: addition, subtraction, division, multiplication, absolute values, and even the power operator. But beyond that, the options used to be extremely thin.
The Math Codeunit in System Application
Thankfully, at some point somebody at Microsoft needed more math functionality. They added a Math codeunit to the System Application app. Here’s how you use it:
var
Math: Codeunit Math;
begin
// Now you can call:
Math.Abs(...);
Math.Acos(...);
Math.Asin(...);
Math.Atan2(...);
// and more...
end;
The Math codeunit provides a wide range of functions:
- Abs — Absolute value
- Acos, Asin, Atan2 — Inverse trigonometric functions
- BigMul — Multiply two integers and get a BigInteger result
- Ceiling and Floor — Rounding in different directions
- Cos, Sin, Tan — Trigonometric functions
- E and Pi — Mathematical constants
- Max and Min — Comparison functions
- Pow — Power function
- Sqrt — Square root
- Truncate — Useful when working with decimals vs. floats
The BigMul Problem
Erik demonstrates an interesting edge case. If you try to multiply two large integers and store the result in a BigInteger variable directly, it won’t work:
var
b: BigInteger;
i: Integer;
begin
i := 2147483647; // some large value
b := i * i; // This wouldn't work!
end;
Microsoft never needed this to work natively. But with the Math codeunit, you can use BigMul:
b := Math.BigMul(i, i); // This works!
Under the Hood: A .NET Wrapper
If you press F12 to go to the definition of the Math codeunit, you’ll see that it’s actually just a wrapper around the .NET System.Math class in the CLR. The functions map directly to their .NET equivalents.
Erik notes one fun detail: the Pi constant in the codeunit contains more decimal places than NASA uses for their calculations.
Extending Math Through Open Source Contributions
What if there’s a function in the .NET Math class that hasn’t been wrapped yet? This is where it gets exciting — the System Application is open source.
The source code lives in Microsoft’s AL-App repository. If you navigate to the modules within the System Application, you’ll find the Math folder containing the single codeunit and its permissions.
Here’s how you can contribute:
- Fork the repository
- Clone the Math codeunit and add your own functionality
- Ensure you include appropriate documentation and follow the existing code style
- Create a pull request to Microsoft
- If it makes sense and looks correct, they’ll accept it — and your code becomes part of Business Central
Erik mentions that he demonstrated this process previously on his channel when he added character encoding support to the Base64 codeunit — showing it’s not only possible but also not terribly difficult.
Why This Matters
The alternative approaches for doing advanced math in AL are far less appealing:
- Implementing math from the ground up in AL — tedious and error-prone
- Calling into JavaScript via control add-ins — tremendously slow and unstable
Neither of these is a good option. Using the Math codeunit from System Application, and contributing back when you need something more, is by far the best path forward.
Conclusion
Business Central’s math capabilities have come a long way from the bare minimum. The Math codeunit in the System Application provides a solid set of functions by wrapping .NET’s System.Math class. And because the System Application is open source, you’re not stuck waiting for Microsoft to add what you need — you can contribute it yourself through a pull request. It’s a great example of how the open-source model benefits the entire Business Central ecosystem, turning “the only thing we get is what somebody else needed” into “this is what I need — here it is, Microsoft.”