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.
Product:
Class:
Registers a callback function to dynamically format the string output of evaluated expressions.
Returns an Item object representing the created format rule. This object can be used later to release the format.
The Format() method allows you to intercept the output of functions like EvalStr and EvaluateStr and apply custom formatting transformations using a callback function. This creates a powerful, dynamic post-processing pipeline for all expression results.
Note: There are two versions of Format(). This one involves using a callback to a function in the host application for the formatting logic, while the other Format definition is done inline.
You can create formatters that apply globally or only to specific data types:
targetDataTypeName and targetDataType parameters, the callback will be applied to the string result of all data types."Double") or a DataType object, you can restrict the formatter to run only when the expression result matches that type. This is ideal for scenarios like formatting numbers as currency, dates into a specific layout, or booleans as "Yes/No".uCalc maintains a separate formatting pipeline for each data type (plus one for global formatters). When you add multiple formatters, they are pushed onto a stack. The execution order is Last-In, First-Out (LIFO):
This layering allows for building up complex formatting from simple, reusable components.
This method returns an Item object. To remove the formatter from the pipeline, call uCalc.Item.Release on this item. This is crucial for temporary formatting rules to avoid memory leaks and unintended side effects.
Also, uCalc.EvalStr has a parameter that suppresses all formatting just for the given expression.
You can view all active formatters by using uc.ListOfItems(ItemIs.Format);.
While languages like C# (string interpolation, String.Format) and Python (f-strings) provide excellent static formatting, uCalc's Format() method offers a different paradigm:
ID: 26
using uCalcSoftware;
var uc = new uCalc();
static void OutputAnswerCB(uCalc.Callback cb) {
cb.ReturnStr("Answer: " + cb.ArgStr(1));
}
static void OutputSymbolCB(uCalc.Callback cb) {
cb.ReturnStr("==> " + cb.ArgStr(1));
}
static void OutputBoolCB(uCalc.Callback cb) {
if (cb.ArgStr(1) == "false") {
cb.ReturnStr("No");
} else if (cb.ArgStr(1) == "true") {
cb.ReturnStr("Yes");
}
}
// This format inserts "Answer: " in front of every result
var OutputAnswer = uc.Format( OutputAnswerCB);
Console.WriteLine(uc.EvalStr("10+20"));
Console.WriteLine(uc.EvalStr("'Hello '+'world'"));
Console.WriteLine(uc.EvalStr("5 > 10"));
Console.WriteLine("---");
// This one inserts ==> in front of the result
// The previously defined "Answer: " output is still prepended as well
var OutputSymbol = uc.Format( OutputSymbolCB);
Console.WriteLine(uc.EvalStr("10+20"));
Console.WriteLine(uc.EvalStr("'Hello '+'world'"));
Console.WriteLine(uc.EvalStr("5 > 10"));
Console.WriteLine("---");
// Causes Boolean values to return Yes or No (instead of true or false)
var OutputBool = uc.Format( OutputBoolCB, "Bool");
Console.WriteLine(uc.EvalStr("10+20"));
Console.WriteLine(uc.EvalStr("'Hello '+'world'"));
Console.WriteLine(uc.EvalStr("5 > 10"));
Console.WriteLine(uc.EvalStr("5 < 10"));
Console.WriteLine("---");
// The previously defined "==>" output is removed
OutputSymbol.Release();
Console.WriteLine(uc.EvalStr("10+20"));
Console.WriteLine(uc.EvalStr("'Hello '+'world'"));
Console.WriteLine(uc.EvalStr("5 > 10"));
Console.WriteLine(uc.EvalStr("5 < 10"));
Answer: 30
Answer: Hello world
Answer: false
---
Answer: ==> 30
Answer: ==> Hello world
Answer: ==> false
---
Answer: ==> 30
Answer: ==> Hello world
Answer: ==> No
Answer: ==> Yes
---
Answer: 30
Answer: Hello world
Answer: No
Answer: Yes using uCalcSoftware; var uc = new uCalc(); static void OutputAnswerCB(uCalc.Callback cb) { cb.ReturnStr("Answer: " + cb.ArgStr(1)); } static void OutputSymbolCB(uCalc.Callback cb) { cb.ReturnStr("==> " + cb.ArgStr(1)); } static void OutputBoolCB(uCalc.Callback cb) { if (cb.ArgStr(1) == "false") { cb.ReturnStr("No"); } else if (cb.ArgStr(1) == "true") { cb.ReturnStr("Yes"); } } // This format inserts "Answer: " in front of every result var OutputAnswer = uc.Format( OutputAnswerCB); Console.WriteLine(uc.EvalStr("10+20")); Console.WriteLine(uc.EvalStr("'Hello '+'world'")); Console.WriteLine(uc.EvalStr("5 > 10")); Console.WriteLine("---"); // This one inserts ==> in front of the result // The previously defined "Answer: " output is still prepended as well var OutputSymbol = uc.Format( OutputSymbolCB); Console.WriteLine(uc.EvalStr("10+20")); Console.WriteLine(uc.EvalStr("'Hello '+'world'")); Console.WriteLine(uc.EvalStr("5 > 10")); Console.WriteLine("---"); // Causes Boolean values to return Yes or No (instead of true or false) var OutputBool = uc.Format( OutputBoolCB, "Bool"); Console.WriteLine(uc.EvalStr("10+20")); Console.WriteLine(uc.EvalStr("'Hello '+'world'")); Console.WriteLine(uc.EvalStr("5 > 10")); Console.WriteLine(uc.EvalStr("5 < 10")); Console.WriteLine("---"); // The previously defined "==>" output is removed OutputSymbol.Release(); Console.WriteLine(uc.EvalStr("10+20")); Console.WriteLine(uc.EvalStr("'Hello '+'world'")); Console.WriteLine(uc.EvalStr("5 > 10")); Console.WriteLine(uc.EvalStr("5 < 10"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
void ucalc_call OutputAnswerCB(uCalcBase::Callback cb) {
cb.ReturnStr("Answer: " + cb.ArgStr(1));
}
void ucalc_call OutputSymbolCB(uCalcBase::Callback cb) {
cb.ReturnStr("==> " + cb.ArgStr(1));
}
void ucalc_call OutputBoolCB(uCalcBase::Callback cb) {
if (cb.ArgStr(1) == "false") {
cb.ReturnStr("No");
} else if (cb.ArgStr(1) == "true") {
cb.ReturnStr("Yes");
}
}
int main() {
uCalc uc;
// This format inserts "Answer: " in front of every result
auto OutputAnswer = uc.Format( OutputAnswerCB);
cout << uc.EvalStr("10+20") << endl;
cout << uc.EvalStr("'Hello '+'world'") << endl;
cout << uc.EvalStr("5 > 10") << endl;
cout << "---" << endl;
// This one inserts ==> in front of the result
// The previously defined "Answer: " output is still prepended as well
auto OutputSymbol = uc.Format( OutputSymbolCB);
cout << uc.EvalStr("10+20") << endl;
cout << uc.EvalStr("'Hello '+'world'") << endl;
cout << uc.EvalStr("5 > 10") << endl;
cout << "---" << endl;
// Causes Boolean values to return Yes or No (instead of true or false)
auto OutputBool = uc.Format( OutputBoolCB, "Bool");
cout << uc.EvalStr("10+20") << endl;
cout << uc.EvalStr("'Hello '+'world'") << endl;
cout << uc.EvalStr("5 > 10") << endl;
cout << uc.EvalStr("5 < 10") << endl;
cout << "---" << endl;
// The previously defined "==>" output is removed
OutputSymbol.Release();
cout << uc.EvalStr("10+20") << endl;
cout << uc.EvalStr("'Hello '+'world'") << endl;
cout << uc.EvalStr("5 > 10") << endl;
cout << uc.EvalStr("5 < 10") << endl;
}
Answer: 30
Answer: Hello world
Answer: false
---
Answer: ==> 30
Answer: ==> Hello world
Answer: ==> false
---
Answer: ==> 30
Answer: ==> Hello world
Answer: ==> No
Answer: ==> Yes
---
Answer: 30
Answer: Hello world
Answer: No
Answer: Yes #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; void ucalc_call OutputAnswerCB(uCalcBase::Callback cb) { cb.ReturnStr("Answer: " + cb.ArgStr(1)); } void ucalc_call OutputSymbolCB(uCalcBase::Callback cb) { cb.ReturnStr("==> " + cb.ArgStr(1)); } void ucalc_call OutputBoolCB(uCalcBase::Callback cb) { if (cb.ArgStr(1) == "false") { cb.ReturnStr("No"); } else if (cb.ArgStr(1) == "true") { cb.ReturnStr("Yes"); } } int main() { uCalc uc; // This format inserts "Answer: " in front of every result auto OutputAnswer = uc.Format( OutputAnswerCB); cout << uc.EvalStr("10+20") << endl; cout << uc.EvalStr("'Hello '+'world'") << endl; cout << uc.EvalStr("5 > 10") << endl; cout << "---" << endl; // This one inserts ==> in front of the result // The previously defined "Answer: " output is still prepended as well auto OutputSymbol = uc.Format( OutputSymbolCB); cout << uc.EvalStr("10+20") << endl; cout << uc.EvalStr("'Hello '+'world'") << endl; cout << uc.EvalStr("5 > 10") << endl; cout << "---" << endl; // Causes Boolean values to return Yes or No (instead of true or false) auto OutputBool = uc.Format( OutputBoolCB, "Bool"); cout << uc.EvalStr("10+20") << endl; cout << uc.EvalStr("'Hello '+'world'") << endl; cout << uc.EvalStr("5 > 10") << endl; cout << uc.EvalStr("5 < 10") << endl; cout << "---" << endl; // The previously defined "==>" output is removed OutputSymbol.Release(); cout << uc.EvalStr("10+20") << endl; cout << uc.EvalStr("'Hello '+'world'") << endl; cout << uc.EvalStr("5 > 10") << endl; cout << uc.EvalStr("5 < 10") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub OutputAnswerCB(ByVal cb As uCalc.Callback)
cb.ReturnStr("Answer: " + cb.ArgStr(1))
End Sub
Public Sub OutputSymbolCB(ByVal cb As uCalc.Callback)
cb.ReturnStr("==> " + cb.ArgStr(1))
End Sub
Public Sub OutputBoolCB(ByVal cb As uCalc.Callback)
If cb.ArgStr(1) = "false" Then
cb.ReturnStr("No")
ElseIf cb.ArgStr(1) = "true" Then
cb.ReturnStr("Yes")
End If
End Sub
Public Sub Main()
Dim uc As New uCalc()
'// This format inserts "Answer: " in front of every result
Dim OutputAnswer = uc.Format(AddressOf OutputAnswerCB)
Console.WriteLine(uc.EvalStr("10+20"))
Console.WriteLine(uc.EvalStr("'Hello '+'world'"))
Console.WriteLine(uc.EvalStr("5 > 10"))
Console.WriteLine("---")
'// This one inserts ==> in front of the result
'// The previously defined "Answer: " output is still prepended as well
Dim OutputSymbol = uc.Format(AddressOf OutputSymbolCB)
Console.WriteLine(uc.EvalStr("10+20"))
Console.WriteLine(uc.EvalStr("'Hello '+'world'"))
Console.WriteLine(uc.EvalStr("5 > 10"))
Console.WriteLine("---")
'// Causes Boolean values to return Yes or No (instead of true or false)
Dim OutputBool = uc.Format(AddressOf OutputBoolCB, "Bool")
Console.WriteLine(uc.EvalStr("10+20"))
Console.WriteLine(uc.EvalStr("'Hello '+'world'"))
Console.WriteLine(uc.EvalStr("5 > 10"))
Console.WriteLine(uc.EvalStr("5 < 10"))
Console.WriteLine("---")
'// The previously defined "==>" output is removed
OutputSymbol.Release()
Console.WriteLine(uc.EvalStr("10+20"))
Console.WriteLine(uc.EvalStr("'Hello '+'world'"))
Console.WriteLine(uc.EvalStr("5 > 10"))
Console.WriteLine(uc.EvalStr("5 < 10"))
End Sub
End Module
Answer: 30
Answer: Hello world
Answer: false
---
Answer: ==> 30
Answer: ==> Hello world
Answer: ==> false
---
Answer: ==> 30
Answer: ==> Hello world
Answer: ==> No
Answer: ==> Yes
---
Answer: 30
Answer: Hello world
Answer: No
Answer: Yes Imports System Imports uCalcSoftware Public Module Program Public Sub OutputAnswerCB(ByVal cb As uCalc.Callback) cb.ReturnStr("Answer: " + cb.ArgStr(1)) End Sub Public Sub OutputSymbolCB(ByVal cb As uCalc.Callback) cb.ReturnStr("==> " + cb.ArgStr(1)) End Sub Public Sub OutputBoolCB(ByVal cb As uCalc.Callback) If cb.ArgStr(1) = "false" Then cb.ReturnStr("No") ElseIf cb.ArgStr(1) = "true" Then cb.ReturnStr("Yes") End If End Sub Public Sub Main() Dim uc As New uCalc() '// This format inserts "Answer: " in front of every result Dim OutputAnswer = uc.Format(AddressOf OutputAnswerCB) Console.WriteLine(uc.EvalStr("10+20")) Console.WriteLine(uc.EvalStr("'Hello '+'world'")) Console.WriteLine(uc.EvalStr("5 > 10")) Console.WriteLine("---") '// This one inserts ==> in front of the result '// The previously defined "Answer: " output is still prepended as well Dim OutputSymbol = uc.Format(AddressOf OutputSymbolCB) Console.WriteLine(uc.EvalStr("10+20")) Console.WriteLine(uc.EvalStr("'Hello '+'world'")) Console.WriteLine(uc.EvalStr("5 > 10")) Console.WriteLine("---") '// Causes Boolean values to return Yes or No (instead of true or false) Dim OutputBool = uc.Format(AddressOf OutputBoolCB, "Bool") Console.WriteLine(uc.EvalStr("10+20")) Console.WriteLine(uc.EvalStr("'Hello '+'world'")) Console.WriteLine(uc.EvalStr("5 > 10")) Console.WriteLine(uc.EvalStr("5 < 10")) Console.WriteLine("---") '// The previously defined "==>" output is removed OutputSymbol.Release() Console.WriteLine(uc.EvalStr("10+20")) Console.WriteLine(uc.EvalStr("'Hello '+'world'")) Console.WriteLine(uc.EvalStr("5 > 10")) Console.WriteLine(uc.EvalStr("5 < 10")) End Sub End Module