uCalc API Version: 5.7.0-preview.1 Released: 7/30/2026

Warning

uCalc API Preview Release Notice:This preview documentation describes the intended behavior of the API. It is not fully accurate or complete.The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.Use of the preview version in your production code is not recommended.

{@Number}

Product: 

Class: 

Remarks

Description: A category matcher that identifies any token defined as a numeric value (e.g., 10, 3.14, 1e-5).

The {@Number} directive is used within a uCalc::Transformer to target numeric data. Because it operates at the tokenization level, it is more robust than a standard numeric regex. It understands the context of a number and treats it as a single unit, regardless of its format.

Supported Formats

By default, {@Number} recognizes:

  • Integers: 42
  • Decimals: 0.99
  • Scientific Notation: 6.022e23
  • Hex/Binary: 0xFF or 0b1010 (if configured in the engine)

Accuracy vs. Regex

A common regex like \d+ might accidentally match digits inside a variable name (like the 3 in data3). Because {@Number} queries the lexer, it only matches tokens that have been explicitly identified as numeric literals, ensuring your transformations don't corrupt variable identifiers.

Inverse Matching with !

The universal inversion operator ! can be applied to this category:

  • {@Number}: Matches a numeric token.
  • {!Number}: Matches any token that is not a number (e.g., operators, strings, or keywords).

Examples

Matching by token type

ID: 176

				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();

t.FromTo("{@String:txt}", "<<InnerQuote={txt}><TxtWithQuotes={txt(0)}>>");
t.FromTo("{@Number:MyNum}", "<NumericValue={MyNum}>");
t.FromTo("{@Bracket:MyBrack}", "<Brack={MyBrack}>");
t.FromTo("{@CloseBracket:CloseBr}", "<CloseBrack={CloseBr}>");
t.FromTo("{@StatementSeparator:Sep}", "<Separator={Sep}>");
t.FromTo("{@Alphanumeric:alpha}", "<Alpha={alpha}>");
t.FromTo("{@Whitespace:ws}", "<whitespace count={@Eval: Length(ws)}>");
t.FromTo("{@Reducible:r}", "<Reducible={r}>");
t.FromTo("{@Newline}", "<New line{@Newline}>");

var s = """
This is   55.2*6 "Hello world";
'Single quote'(parenth)
""";

Console.WriteLine(t.Filter(s).Matches.Text);
				
			
<Alpha=This>
<whitespace count=1>
<Alpha=is>
<whitespace count=3>
<NumericValue=55.2>
<Reducible=*>
<NumericValue=6>
<whitespace count=1>
<<InnerQuote=Hello world><TxtWithQuotes="Hello world">>
<Separator=;>
<New line
>
<<InnerQuote=Single quote><TxtWithQuotes='Single quote'>>
<Brack=(>
<Alpha=parenth>
<CloseBrack=)>
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();

   t.FromTo("{@String:txt}", "<<InnerQuote={txt}><TxtWithQuotes={txt(0)}>>");
   t.FromTo("{@Number:MyNum}", "<NumericValue={MyNum}>");
   t.FromTo("{@Bracket:MyBrack}", "<Brack={MyBrack}>");
   t.FromTo("{@CloseBracket:CloseBr}", "<CloseBrack={CloseBr}>");
   t.FromTo("{@StatementSeparator:Sep}", "<Separator={Sep}>");
   t.FromTo("{@Alphanumeric:alpha}", "<Alpha={alpha}>");
   t.FromTo("{@Whitespace:ws}", "<whitespace count={@Eval: Length(ws)}>");
   t.FromTo("{@Reducible:r}", "<Reducible={r}>");
   t.FromTo("{@Newline}", "<New line{@Newline}>");

   auto s = R"(This is   55.2*6 "Hello world";
'Single quote'(parenth))";

   cout << t.Filter(s).Matches().Text() << endl;
}
				
			
<Alpha=This>
<whitespace count=1>
<Alpha=is>
<whitespace count=3>
<NumericValue=55.2>
<Reducible=*>
<NumericValue=6>
<whitespace count=1>
<<InnerQuote=Hello world><TxtWithQuotes="Hello world">>
<Separator=;>
<New line
>
<<InnerQuote=Single quote><TxtWithQuotes='Single quote'>>
<Brack=(>
<Alpha=parenth>
<CloseBrack=)>
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      
      t.FromTo("{@String:txt}", "<<InnerQuote={txt}><TxtWithQuotes={txt(0)}>>")
      t.FromTo("{@Number:MyNum}", "<NumericValue={MyNum}>")
      t.FromTo("{@Bracket:MyBrack}", "<Brack={MyBrack}>")
      t.FromTo("{@CloseBracket:CloseBr}", "<CloseBrack={CloseBr}>")
      t.FromTo("{@StatementSeparator:Sep}", "<Separator={Sep}>")
      t.FromTo("{@Alphanumeric:alpha}", "<Alpha={alpha}>")
      t.FromTo("{@Whitespace:ws}", "<whitespace count={@Eval: Length(ws)}>")
      t.FromTo("{@Reducible:r}", "<Reducible={r}>")
      t.FromTo("{@Newline}", "<New line{@Newline}>")
      
      Dim s = "This is   55.2*6 ""Hello world"";
'Single quote'(parenth)"
      
      Console.WriteLine(t.Filter(s).Matches.Text)
   End Sub
End Module
				
			
<Alpha=This>
<whitespace count=1>
<Alpha=is>
<whitespace count=3>
<NumericValue=55.2>
<Reducible=*>
<NumericValue=6>
<whitespace count=1>
<<InnerQuote=Hello world><TxtWithQuotes="Hello world">>
<Separator=;>
<New line
>
<<InnerQuote=Single quote><TxtWithQuotes='Single quote'>>
<Brack=(>
<Alpha=parenth>
<CloseBrack=)>
(Real World: Currency Formatter) Finding raw numbers in a text stream and converting them to a formatted currency string.

ID: 251

				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();
t.FromTo("Price: {@Number:amt}", "Price: ${amt}");

string input = "Item A Price: 19.99, Item B Price: 5";
Console.WriteLine(t.Transform(input));
				
			
Item A Price: $19.99, Item B Price: $5
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();
   t.FromTo("Price: {@Number:amt}", "Price: ${amt}");

   string input = "Item A Price: 19.99, Item B Price: 5";
   cout << t.Transform(input) << endl;
}
				
			
Item A Price: $19.99, Item B Price: $5
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      t.FromTo("Price: {@Number:amt}", "Price: ${amt}")
      
      Dim input As String = "Item A Price: 19.99, Item B Price: 5"
      Console.WriteLine(t.Transform(input))
   End Sub
End Module
				
			
Item A Price: $19.99, Item B Price: $5
Identifying all numbers in an expression and wrapping them in a "Num" tag.

ID: 909

See: {@Number}
				
					using uCalcSoftware;

var uc = new uCalc();
var t = new uCalc.Transformer();
t.FromTo("{@Number:n}", "Num({n})");

Console.WriteLine(t.Transform("price = 50 + 5.50"));
				
			
price = Num(50) + Num(5.50)
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uCalc::Transformer t;
   t.FromTo("{@Number:n}", "Num({n})");

   cout << t.Transform("price = 50 + 5.50") << endl;
}
				
			
price = Num(50) + Num(5.50)
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t As New uCalc.Transformer()
      t.FromTo("{@Number:n}", "Num({n})")
      
      Console.WriteLine(t.Transform("price = 50 + 5.50"))
   End Sub
End Module
				
			
price = Num(50) + Num(5.50)
Verifying that `{@Number}` correctly ignores digits that are part of other tokens (like strings or identifiers).

ID: 910

See: {@Number}
				
					using uCalcSoftware;

var uc = new uCalc();
var t = new uCalc.Transformer();
t.FromTo("{@Number}", "FOUND");

// The '2' in 'var2' and the '100' in the string should NOT match
Console.WriteLine(t.Transform("""
var2 = "count is 100" + 50
"""));
				
			
var2 = "count is 100" + FOUND
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uCalc::Transformer t;
   t.FromTo("{@Number}", "FOUND");

   // The '2' in 'var2' and the '100' in the string should NOT match
   cout << t.Transform(R"(var2 = "count is 100" + 50)") << endl;
}
				
			
var2 = "count is 100" + FOUND
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t As New uCalc.Transformer()
      t.FromTo("{@Number}", "FOUND")
      
      '// The '2' in 'var2' and the '100' in the string should NOT match
      Console.WriteLine(t.Transform("var2 = ""count is 100"" + 50"))
   End Sub
End Module
				
			
var2 = "count is 100" + FOUND