Creates a domain-specific currency conversion syntax using the ExpressionTransformer, the correct tool for multi-word patterns.
ID: 1225
See: Dynamic Syntax
using uCalcSoftware;
var uc = new uCalc();
// Use the ExpressionTransformer for multi-word syntax.
var t = uc.ExpressionTransformer;
// Note: Captured variables are passed to @Eval as text
// Double() converts the text to Double a precision value
uc.Format("Result = Format('{:.2f}', Double(Result))", uc.DataTypeOf("Double"));
t.FromTo("{@Number:amount} USD to EUR", "({@Eval: Double(amount) * 0.92})");
t.FromTo("{@Number:amount} EUR to USD", "({@Eval: Double(amount) / 0.92})");
Console.WriteLine($"100 USD is approx. {uc.EvalStr("100 USD to EUR")} EUR");
Console.WriteLine($"120 EUR is approx. {uc.EvalStr("120 EUR to USD")} USD");
100 USD is approx. 92.00 EUR
120 EUR is approx. 130.43 USD using uCalcSoftware; var uc = new uCalc(); // Use the ExpressionTransformer for multi-word syntax. var t = uc.ExpressionTransformer; // Note: Captured variables are passed to @Eval as text // Double() converts the text to Double a precision value uc.Format("Result = Format('{:.2f}', Double(Result))", uc.DataTypeOf("Double")); t.FromTo("{@Number:amount} USD to EUR", "({@Eval: Double(amount) * 0.92})"); t.FromTo("{@Number:amount} EUR to USD", "({@Eval: Double(amount) / 0.92})"); Console.WriteLine($"100 USD is approx. {uc.EvalStr("100 USD to EUR")} EUR"); Console.WriteLine($"120 EUR is approx. {uc.EvalStr("120 EUR to USD")} USD");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// Use the ExpressionTransformer for multi-word syntax.
auto t = uc.ExpressionTransformer();
// Note: Captured variables are passed to @Eval as text
// Double() converts the text to Double a precision value
uc.Format("Result = Format('{:.2f}', Double(Result))", uc.DataTypeOf("Double"));
t.FromTo("{@Number:amount} USD to EUR", "({@Eval: Double(amount) * 0.92})");
t.FromTo("{@Number:amount} EUR to USD", "({@Eval: Double(amount) / 0.92})");
cout << "100 USD is approx. " << uc.EvalStr("100 USD to EUR") << " EUR" << endl;
cout << "120 EUR is approx. " << uc.EvalStr("120 EUR to USD") << " USD" << endl;
}
100 USD is approx. 92.00 EUR
120 EUR is approx. 130.43 USD #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // Use the ExpressionTransformer for multi-word syntax. auto t = uc.ExpressionTransformer(); // Note: Captured variables are passed to @Eval as text // Double() converts the text to Double a precision value uc.Format("Result = Format('{:.2f}', Double(Result))", uc.DataTypeOf("Double")); t.FromTo("{@Number:amount} USD to EUR", "({@Eval: Double(amount) * 0.92})"); t.FromTo("{@Number:amount} EUR to USD", "({@Eval: Double(amount) / 0.92})"); cout << "100 USD is approx. " << uc.EvalStr("100 USD to EUR") << " EUR" << endl; cout << "120 EUR is approx. " << uc.EvalStr("120 EUR to USD") << " USD" << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// Use the ExpressionTransformer for multi-word syntax.
Dim t = uc.ExpressionTransformer
'// Note: Captured variables are passed to @Eval as text
'// Double() converts the text to Double a precision value
uc.Format("Result = Format('{:.2f}', Double(Result))", uc.DataTypeOf("Double"))
t.FromTo("{@Number:amount} USD to EUR", "({@Eval: Double(amount) * 0.92})")
t.FromTo("{@Number:amount} EUR to USD", "({@Eval: Double(amount) / 0.92})")
Console.WriteLine($"100 USD is approx. {uc.EvalStr("100 USD to EUR")} EUR")
Console.WriteLine($"120 EUR is approx. {uc.EvalStr("120 EUR to USD")} USD")
End Sub
End Module
100 USD is approx. 92.00 EUR
120 EUR is approx. 130.43 USD Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// Use the ExpressionTransformer for multi-word syntax. Dim t = uc.ExpressionTransformer '// Note: Captured variables are passed to @Eval as text '// Double() converts the text to Double a precision value uc.Format("Result = Format('{:.2f}', Double(Result))", uc.DataTypeOf("Double")) t.FromTo("{@Number:amount} USD to EUR", "({@Eval: Double(amount) * 0.92})") t.FromTo("{@Number:amount} EUR to USD", "({@Eval: Double(amount) / 0.92})") Console.WriteLine($"100 USD is approx. {uc.EvalStr("100 USD to EUR")} EUR") Console.WriteLine($"120 EUR is approx. {uc.EvalStr("120 EUR to USD")} USD") End Sub End Module