-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHelloWorldMoneta.cs
38 lines (31 loc) · 1013 Bytes
/
HelloWorldMoneta.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using Bogoware.Moneta;
using Bogoware.Moneta.CommonCurrencies;
namespace MonetaHelloWorld;
public static class HelloWorldMoneta
{
public static void BadCode()
{
using var moneta = new MonetaContext();
var unitPrice = moneta.Dollar(1.12m);
var quantity = 12.43424m;
var finalPrice = unitPrice * quantity;
Console.WriteLine($"Unit price: {unitPrice}");
Console.WriteLine($"Quantity: {quantity}");
Console.WriteLine($"Final price: {finalPrice}");
} // an exception will be thrown because rounding errors occurred and were not handled
public static void GoodCode()
{
using var moneta = new MonetaContext();
var unitPrice = moneta.Dollar(1.12m);
var quantity = 12.43424m;
var finalPrice = unitPrice * quantity;
Console.WriteLine($"Unit price: {unitPrice}");
Console.WriteLine($"Quantity: {quantity}");
Console.WriteLine($"Final price: {finalPrice}");
if (moneta.HasRoundingErrors)
{
// Handle rounding errors as you prefer
moneta.ClearRoundingErrors();
}
}
}