Calculates a total price using predefined variables and demonstrates the effect of output formatting.

ID: 338

See: EvalStr
				
					using uCalcSoftware;

var uc = new uCalc();
// Define some context for the expression
uc.DefineVariable("price = 49.99");
uc.DefineVariable("quantity = 3");
uc.DefineConstant("TAX_RATE = 0.0825");

// Define a format for currency output
uc.Format("DataType: Double, Def: result = '$' + result");

// Expression to calculate total price, using variables
var expression = "price * quantity * (1 + TAX_RATE)";

// Evaluate with formatting enabled
Console.WriteLine($"Formatted Total: {uc.EvalStr(expression, true)}");

// Evaluate with formatting disabled
Console.WriteLine($"Raw Total: {uc.EvalStr(expression, false)}");
				
			
Formatted Total: $162.342525
Raw Total: 162.342525
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   // Define some context for the expression
   uc.DefineVariable("price = 49.99");
   uc.DefineVariable("quantity = 3");
   uc.DefineConstant("TAX_RATE = 0.0825");

   // Define a format for currency output
   uc.Format("DataType: Double, Def: result = '$' + result");

   // Expression to calculate total price, using variables
   auto expression = "price * quantity * (1 + TAX_RATE)";

   // Evaluate with formatting enabled
   cout << "Formatted Total: " << uc.EvalStr(expression, true) << endl;

   // Evaluate with formatting disabled
   cout << "Raw Total: " << uc.EvalStr(expression, false) << endl;
}
				
			
Formatted Total: $162.342525
Raw Total: 162.342525
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      '// Define some context for the expression
      uc.DefineVariable("price = 49.99")
      uc.DefineVariable("quantity = 3")
      uc.DefineConstant("TAX_RATE = 0.0825")
      
      '// Define a format for currency output
      uc.Format("DataType: Double, Def: result = '$' + result")
      
      '// Expression to calculate total price, using variables
      Dim expression = "price * quantity * (1 + TAX_RATE)"
      
      '// Evaluate with formatting enabled
      Console.WriteLine($"Formatted Total: {uc.EvalStr(expression, true)}")
      
      '// Evaluate with formatting disabled
      Console.WriteLine($"Raw Total: {uc.EvalStr(expression, false)}")
   End Sub
End Module
				
			
Formatted Total: $162.342525
Raw Total: 162.342525