Practical: Using the C++ style `Format()` function for currency and text alignment.
ID: 352
using uCalcSoftware;
var uc = new uCalc();
// Rule 1: Format Doubles as currency with two decimal places.
var doubleType = uc.DataTypeOf(BuiltInType.Float_Double);
uc.Format("Result = '$' + Format('{:.2f}', double(Result))", doubleType);
// Rule 2: Center-align strings in a 15-character field padded with '-'.
var strType = uc.DataTypeOf(BuiltInType.String);
uc.Format("Result = Format('{:-^15}', Result)", strType);
Console.WriteLine($"Price: {uc.EvalStr("199.999")}");
Console.WriteLine($"Discount: {uc.EvalStr("7.5")}");
Console.WriteLine($"Label: {uc.EvalStr("'Summary'")}");
Price: $200.00
Discount: $7.50
Label: ----Summary---- using uCalcSoftware; var uc = new uCalc(); // Rule 1: Format Doubles as currency with two decimal places. var doubleType = uc.DataTypeOf(BuiltInType.Float_Double); uc.Format("Result = '$' + Format('{:.2f}', double(Result))", doubleType); // Rule 2: Center-align strings in a 15-character field padded with '-'. var strType = uc.DataTypeOf(BuiltInType.String); uc.Format("Result = Format('{:-^15}', Result)", strType); Console.WriteLine($"Price: {uc.EvalStr("199.999")}"); Console.WriteLine($"Discount: {uc.EvalStr("7.5")}"); Console.WriteLine($"Label: {uc.EvalStr("'Summary'")}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// Rule 1: Format Doubles as currency with two decimal places.
auto doubleType = uc.DataTypeOf(BuiltInType::Float_Double);
uc.Format("Result = '$' + Format('{:.2f}', double(Result))", doubleType);
// Rule 2: Center-align strings in a 15-character field padded with '-'.
auto strType = uc.DataTypeOf(BuiltInType::String);
uc.Format("Result = Format('{:-^15}', Result)", strType);
cout << "Price: " << uc.EvalStr("199.999") << endl;
cout << "Discount: " << uc.EvalStr("7.5") << endl;
cout << "Label: " << uc.EvalStr("'Summary'") << endl;
}
Price: $200.00
Discount: $7.50
Label: ----Summary---- #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // Rule 1: Format Doubles as currency with two decimal places. auto doubleType = uc.DataTypeOf(BuiltInType::Float_Double); uc.Format("Result = '$' + Format('{:.2f}', double(Result))", doubleType); // Rule 2: Center-align strings in a 15-character field padded with '-'. auto strType = uc.DataTypeOf(BuiltInType::String); uc.Format("Result = Format('{:-^15}', Result)", strType); cout << "Price: " << uc.EvalStr("199.999") << endl; cout << "Discount: " << uc.EvalStr("7.5") << endl; cout << "Label: " << uc.EvalStr("'Summary'") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// Rule 1: Format Doubles as currency with two decimal places.
Dim doubleType = uc.DataTypeOf(BuiltInType.Float_Double)
uc.Format("Result = '$' + Format('{:.2f}', double(Result))", doubleType)
'// Rule 2: Center-align strings in a 15-character field padded with '-'.
Dim strType = uc.DataTypeOf(BuiltInType.String)
uc.Format("Result = Format('{:-^15}', Result)", strType)
Console.WriteLine($"Price: {uc.EvalStr("199.999")}")
Console.WriteLine($"Discount: {uc.EvalStr("7.5")}")
Console.WriteLine($"Label: {uc.EvalStr("'Summary'")}")
End Sub
End Module
Price: $200.00
Discount: $7.50
Label: ----Summary---- Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// Rule 1: Format Doubles as currency with two decimal places. Dim doubleType = uc.DataTypeOf(BuiltInType.Float_Double) uc.Format("Result = '$' + Format('{:.2f}', double(Result))", doubleType) '// Rule 2: Center-align strings in a 15-character field padded with '-'. Dim strType = uc.DataTypeOf(BuiltInType.String) uc.Format("Result = Format('{:-^15}', Result)", strType) Console.WriteLine($"Price: {uc.EvalStr("199.999")}") Console.WriteLine($"Discount: {uc.EvalStr("7.5")}") Console.WriteLine($"Label: {uc.EvalStr("'Summary'")}") End Sub End Module