NCalc 7.0.0
dotnet add package NCalc --version 7.0.0
NuGet\Install-Package NCalc -Version 7.0.0
<PackageReference Include="NCalc" Version="7.0.0" />
<PackageVersion Include="NCalc" Version="7.0.0" />
<PackageReference Include="NCalc" />
paket add NCalc --version 7.0.0
#r "nuget: NCalc, 7.0.0"
#:package NCalc@7.0.0
#addin nuget:?package=NCalc&version=7.0.0
#tool nuget:?package=NCalc&version=7.0.0
NCalc
NCalc is a fast, lightweight expression evaluator for .NET. It parses and evaluates mathematical and logical expressions with literals, operators, parameters, built-in functions, and custom functions.
NCalc targets modern .NET, .NET Standard 2.0, and .NET Framework 4.8.
Want to try it first? Open the NCalc playground and run expressions directly in your browser powered by Blazor WASM.
Documentation
Start with the NCalc docs for the full language reference, runtime options, plugins, and API reference.
Useful entry points:
Install
Use NCalc for the expression engine:
dotnet add package NCalc
NCalc, NCalcSync, and NCalcAsync are redirect packages that currently point directly to NCalc.Core, preserving compatibility from before the community efforts were consolidated into the same repository.
Add optional packages only when you need them:
dotnet add package NCalc.LambdaCompilation
dotnet add package NCalc.DependencyInjection
Quick Examples
Evaluate an expression
using NCalc;
var result = new Expression("2 + 3 * 5").Evaluate();
// 17
Use parameters
var expression = new Expression("Round(Pow([x], 2) + [offset], 2)");
expression.Parameters["x"] = 3.14;
expression.Parameters["offset"] = 10;
var result = expression.Evaluate();
// 19.86
Add custom functions
var expression = new Expression("SecretOperation(3, 6)");
expression.Functions["SecretOperation"] = args =>
(int)args.Evaluate(0) + (int)args.Evaluate(1);
var result = expression.Evaluate();
// 9
Compile to a lambda
Install NCalc.LambdaCompilation first.
using NCalc.LambdaCompilation;
var expression = new Expression("1 + 2");
Func<int> function = expression.ToLambda<int>();
var result = function();
// 3
For data types, operators, built-in functions, async evaluation, caching, expression serialization, and advanced configuration, check the docs.
Help
Open an issue for bugs or usage problems. Include the expression, the expected result, the actual result, and your NCalc version.
Learn More
Related Projects
| Project | Description |
|---|---|
| FastExpressionCompiler | Fast compiler for C# expression trees. NCalc uses it for lambda compilation. |
| Jint | JavaScript interpreter for .NET by Sebastien Ros, the original author of NCalc. |
| JJMasterData | Runtime form generator that uses NCalc for field visibility and other dynamic behavior. |
| NCalc101 | Web application for trying NCalc expressions, developed by Panoramic Data. |
| NCalcJS | TypeScript/JavaScript port of NCalc. |
| PanoramicData.NCalcExtensions | Extension functions for NCalc, including string functions, switch, if, in, typeOf, and cast. |
| Parlot | Fast and lightweight parser creation tools by Sebastien Ros. NCalc uses Parlot in its default parser. |
Using NCalc? Create a PR and add your project here!
Versioning
NCalc uses Nerdbank.GitVersioning. Each library build can be traced back to the original git commit. Read more in the release documentation.
Star History
<a href="https://star-history.com/#ncalc/ncalc&Date"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=ncalc/ncalc&type=Date&theme=dark" /> <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=ncalc/ncalc&type=Date" /> <img alt="Star History Chart" src="https://api.star-history.com/svg?repos=ncalc/ncalc&type=Date" /> </picture> </a>
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.2
- NCalc.Core (>= 7.0.0)
-
.NETStandard 2.0
- NCalc.Core (>= 7.0.0)
-
net10.0
- NCalc.Core (>= 7.0.0)
-
net8.0
- NCalc.Core (>= 7.0.0)
NuGet packages (27)
Showing the top 5 NuGet packages that depend on NCalc:
| Package | Downloads |
|---|---|
|
SautinSoft.HtmlToRtf
HTML to RTF .Net is 100% C# assembly to convert HTML documents into RTF, DOCX and Text formats. Can also Merge RTF documents and replace text in them. Absolutely standalone solution, doesn't require MS Office or any other. Requires only .NET Framework 4.6.2 and up or .NET 6.0 and up. The component can read and parse all types of HTML: HTML 3.2, HTML 4.01, HTML 5 with CSS and XHTML 1.01. The component has own HTML parser, DOCX and RTF writers. |
|
|
SautinSoft.Document
Document .Net is 100% C# managed library which gives you API to create, parse, load, modify, convert, edit, generate pie charts, merge, do mail merge and digitally sign documents in PDF, DOCX, RTF, HTML and Text formats. Rasterize documents to Images and render to WPF Framework Element. + Completely created in managed C#. No Microsoft Office automation. + Has own DOCX parser and writer according to ECMA-376 specification. + Has own RTF parser and writer according to RTF 1.8 specification. + Has own PDF parser and writer according to PDF reference 1.7. + Has own HTML writer according to HTML5 reference. + Create PDF/A compliance documents. + Digitally sign PDF documents. + Multi-platform: Windows / macOS / Linux. |
|
|
RS.Tasks
Description |
|
|
SuperXML
SuperXml is just a light weight and easy to use templating engine library, useful to create string and xml templates |
|
|
appstitch.LightSwitch
app-stitch is a visually simple yet powerful way of designing business rules. Combine the many channels to stitch different apps together and save hours on auditing, authentication, automation and validation. |
GitHub repositories (5)
Showing the top 5 popular GitHub repositories that depend on NCalc:
| Repository | Stars |
|---|---|
|
IsNemoEqualTrue/monitor-table-change-with-sqltabledependency
Get SQL Server notification on record table change
|
|
|
nkdAgility/azure-devops-migration-tools
Azure DevOps Migration Tools allow you to migrate Teams, Backlogs, Work Items, Tasks, Test Cases, and Plans & Suits from one Project to another in Azure DevOps / TFS both within the same Organisation, and between Organisations.
|
|
|
tumcms/TUM.CMS.VPLControl
TUM.CMS.VplControl is a WPF based Visual Programming Control for .Net.
|
|
|
elgarf/vMixUTC
Customizable controller for vMix
|
|
|
Platonymous/Stardew-Valley-Mods
A collection of mods for Stardew Valley
|