Skip to content

Commit f63f1ec

Browse files
authored
Update README.md
1 parent 5c8c348 commit f63f1ec

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
Calculates the value of a math expression from a string returning a decimal.
33
Supports variables and user defined operators.
44

5+
### Creating and using a calculator
56
```csharp
6-
// Evaluating a simple expression
77
Calculator myCalculator = new Calculator();
88
decimal result = myCalculator.Evaluate("1 * (2 - 3) ^ 2"); // 1
99
@@ -16,8 +16,8 @@ myCalculator.AddOperator("max", (a, b) => a > b ? a : b, Precedence.Power);
1616
decimal result = myCalculator.Evaluate("2 * 3 max 4"); // 8
1717
```
1818

19-
```csharp
20-
// Using a variables collection
19+
### Creating and using variables
20+
```csharp
2121
Replacements variables = new Replacements
2222
{
2323
["a"] = 5,
@@ -32,8 +32,9 @@ myCalculator.Replace("b", 1);
3232
decimal result = calculator.Evaluate("{a} + 2 * {b} + {PI}"); // 7.1415926535897931
3333
```
3434

35+
### Using the static api: SMath
3536
```csharp
36-
// Using the static class SMath
37+
// Same API as a calculator instance except the Evaluate method
3738
decimal result = SMath.Evaluate("1 + 1"); // 2
3839
decimal result = SMath.Evaluate("1 + {myVar}", new Replacements { ["myVar"] = 1 }); // 2
3940
```

0 commit comments

Comments
 (0)