Specifies the formatting style to apply when converting evaluated results or values to strings.
Product:
Class:
Warning
uCalc API Preview Release Notice:The uCalc engine has successfully transitioned to modern cross-platform environments.The next phase envolves some structural changes, performance optimizations, and API refinements.The API is subject to breaking changes prior to the stable release. Please evaluate the preview version thoroughly before production use.
| Name ▲ ▼ | Value ▲ ▼ | Description ▲ ▼ |
|---|---|---|
| None | Applies no custom formatting. Bypasses any global rules defined via uCalc.Format() and returns the raw, default string representation of the value. | |
| Default | Applies user-defined formatting rules (established via uCalc.Format()) if any exist for the value's data type. If no user-defined format exists, numeric values fall back to General notation with 15 digits of precision. | |
| General | Formats numeric values using general notation (automatically choosing between fixed-point and scientific notation based on the number's magnitude and precision). Non-numeric types fall back to Default. | |
| Scientific | Formats numeric values using scientific (exponential) notation (e.g., 1.234e+03). Non-numeric types fall back to Default. | |
| Fixed | Formats numeric values using fixed-point decimal notation (e.g., 1234.56). Non-numeric types fall back to Default. | |
| Hex | Formats numeric values using hexadecimal floating-point or integer notation. Non-numeric types fall back to Default. |
The FormatStyle enumeration is used with string-returning methods such as uCalc.EvalStr, Expression.EvaluateStr, uCalc.ValueAt, DataType.ToString, and Item.ValueStr. It provides a fast, standardized way to control how numeric values are formatted without needing to write custom format expressions or define global rules.
precision ParameterMethods that accept a FormatStyle argument also provide an optional precision parameter (which defaults to -1):
precision is omitted (or -1):FormatStyle.Default uses 15 digits of precision for numeric values (unless overridden by a global uCalc.Format() rule).General, Scientific, Fixed, Hex) use the underlying conversion engine's shortest accurate representation (or standard default precision for that notation).precision is specified (e.g., precision = 4):General, precision specifies the maximum number of significant digits.Fixed, Scientific, and Hex, precision typically specifies the exact number of digits to appear after the decimal/radix point.uCalc.Format() RulesFormatStyle.Default is the only setting that automatically triggers the global formatting pipeline defined by uCalc.Format() for numeric types.FormatStyle.None explicitly bypasses the global formatting pipeline, allowing you to inspect the raw output of an expression or variable even when global formatters are active.General, Scientific, Fixed, Hex) format numeric values directly according to the requested notation rather than passing them through global uCalc.Format() rules. (If the evaluated result is non-numeric, such as a String, these styles revert to Default behavior).ID: 1475
using uCalcSoftware;
var uc = new uCalc();
var expr = uc.Parse("12345.6789");
// Default (General with up to 15 digits)
Console.WriteLine(expr.EvaluateStr(FormatStyle.Default));
// Fixed notation with 2 decimal places
Console.WriteLine(expr.EvaluateStr(FormatStyle.Fixed, 2));
// Scientific notation with 3 decimal places
Console.WriteLine(expr.EvaluateStr(FormatStyle.Scientific, 3));
// General notation constrained to 4 significant digits
Console.WriteLine(expr.EvaluateStr(FormatStyle.General, 4));
// Hexadecimal floating-point notation
Console.WriteLine(expr.EvaluateStr(FormatStyle.Hex));
12345.6789
12345.68
1.235e+04
1.235e+04
1.81cd6e631f8a1p+13 using uCalcSoftware; var uc = new uCalc(); var expr = uc.Parse("12345.6789"); // Default (General with up to 15 digits) Console.WriteLine(expr.EvaluateStr(FormatStyle.Default)); // Fixed notation with 2 decimal places Console.WriteLine(expr.EvaluateStr(FormatStyle.Fixed, 2)); // Scientific notation with 3 decimal places Console.WriteLine(expr.EvaluateStr(FormatStyle.Scientific, 3)); // General notation constrained to 4 significant digits Console.WriteLine(expr.EvaluateStr(FormatStyle.General, 4)); // Hexadecimal floating-point notation Console.WriteLine(expr.EvaluateStr(FormatStyle.Hex));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto expr = uc.Parse("12345.6789");
// Default (General with up to 15 digits)
cout << expr.EvaluateStr(FormatStyle::Default) << endl;
// Fixed notation with 2 decimal places
cout << expr.EvaluateStr(FormatStyle::Fixed, 2) << endl;
// Scientific notation with 3 decimal places
cout << expr.EvaluateStr(FormatStyle::Scientific, 3) << endl;
// General notation constrained to 4 significant digits
cout << expr.EvaluateStr(FormatStyle::General, 4) << endl;
// Hexadecimal floating-point notation
cout << expr.EvaluateStr(FormatStyle::Hex) << endl;
}
12345.6789
12345.68
1.235e+04
1.235e+04
1.81cd6e631f8a1p+13 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto expr = uc.Parse("12345.6789"); // Default (General with up to 15 digits) cout << expr.EvaluateStr(FormatStyle::Default) << endl; // Fixed notation with 2 decimal places cout << expr.EvaluateStr(FormatStyle::Fixed, 2) << endl; // Scientific notation with 3 decimal places cout << expr.EvaluateStr(FormatStyle::Scientific, 3) << endl; // General notation constrained to 4 significant digits cout << expr.EvaluateStr(FormatStyle::General, 4) << endl; // Hexadecimal floating-point notation cout << expr.EvaluateStr(FormatStyle::Hex) << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim expr = uc.Parse("12345.6789")
'// Default (General with up to 15 digits)
Console.WriteLine(expr.EvaluateStr(FormatStyle.Default))
'// Fixed notation with 2 decimal places
Console.WriteLine(expr.EvaluateStr(FormatStyle.Fixed, 2))
'// Scientific notation with 3 decimal places
Console.WriteLine(expr.EvaluateStr(FormatStyle.Scientific, 3))
'// General notation constrained to 4 significant digits
Console.WriteLine(expr.EvaluateStr(FormatStyle.General, 4))
'// Hexadecimal floating-point notation
Console.WriteLine(expr.EvaluateStr(FormatStyle.Hex))
End Sub
End Module
12345.6789
12345.68
1.235e+04
1.235e+04
1.81cd6e631f8a1p+13 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim expr = uc.Parse("12345.6789") '// Default (General with up to 15 digits) Console.WriteLine(expr.EvaluateStr(FormatStyle.Default)) '// Fixed notation with 2 decimal places Console.WriteLine(expr.EvaluateStr(FormatStyle.Fixed, 2)) '// Scientific notation with 3 decimal places Console.WriteLine(expr.EvaluateStr(FormatStyle.Scientific, 3)) '// General notation constrained to 4 significant digits Console.WriteLine(expr.EvaluateStr(FormatStyle.General, 4)) '// Hexadecimal floating-point notation Console.WriteLine(expr.EvaluateStr(FormatStyle.Hex)) End Sub End Module
ID: 1476
using uCalcSoftware;
var uc = new uCalc();
// Define a global format rule for Double values
uc.Format("Def: Result = Format('${:.2f}', double(Result))", uc.DataTypeOf("Double"));
// FormatStyle.Default (or omitting the argument) applies the global rule
Console.WriteLine(uc.EvalStr("50 * 1.25", FormatStyle.Default));
// FormatStyle.None bypasses the global rule and returns the raw value
Console.WriteLine(uc.EvalStr("50 * 1.25", FormatStyle.None));
$62.50
62.5 using uCalcSoftware; var uc = new uCalc(); // Define a global format rule for Double values uc.Format("Def: Result = Format('${:.2f}', double(Result))", uc.DataTypeOf("Double")); // FormatStyle.Default (or omitting the argument) applies the global rule Console.WriteLine(uc.EvalStr("50 * 1.25", FormatStyle.Default)); // FormatStyle.None bypasses the global rule and returns the raw value Console.WriteLine(uc.EvalStr("50 * 1.25", FormatStyle.None));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// Define a global format rule for Double values
uc.Format("Def: Result = Format('${:.2f}', double(Result))", uc.DataTypeOf("Double"));
// FormatStyle.Default (or omitting the argument) applies the global rule
cout << uc.EvalStr("50 * 1.25", FormatStyle::Default) << endl;
// FormatStyle.None bypasses the global rule and returns the raw value
cout << uc.EvalStr("50 * 1.25", FormatStyle::None) << endl;
}
$62.50
62.5 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // Define a global format rule for Double values uc.Format("Def: Result = Format('${:.2f}', double(Result))", uc.DataTypeOf("Double")); // FormatStyle.Default (or omitting the argument) applies the global rule cout << uc.EvalStr("50 * 1.25", FormatStyle::Default) << endl; // FormatStyle.None bypasses the global rule and returns the raw value cout << uc.EvalStr("50 * 1.25", FormatStyle::None) << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// Define a global format rule for Double values
uc.Format("Def: Result = Format('${:.2f}', double(Result))", uc.DataTypeOf("Double"))
'// FormatStyle.Default (or omitting the argument) applies the global rule
Console.WriteLine(uc.EvalStr("50 * 1.25", FormatStyle.Default))
'// FormatStyle.None bypasses the global rule and returns the raw value
Console.WriteLine(uc.EvalStr("50 * 1.25", FormatStyle.None))
End Sub
End Module
$62.50
62.5 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// Define a global format rule for Double values uc.Format("Def: Result = Format('${:.2f}', double(Result))", uc.DataTypeOf("Double")) '// FormatStyle.Default (or omitting the argument) applies the global rule Console.WriteLine(uc.EvalStr("50 * 1.25", FormatStyle.Default)) '// FormatStyle.None bypasses the global rule and returns the raw value Console.WriteLine(uc.EvalStr("50 * 1.25", FormatStyle.None)) End Sub End Module
This page last modified on: