-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
40 lines (33 loc) · 794 Bytes
/
main.go
File metadata and controls
40 lines (33 loc) · 794 Bytes
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
39
40
// Example of how to use the distribution core package
package main
import (
"fmt"
"github.com/shopspring/decimal"
"github.com/barugoo/distribution/examples/products"
)
func main() {
ps := []products.Product{
{
Price: decimal.NewFromFloat(10),
VatRate: 5,
},
{
Price: decimal.NewFromFloat(15),
VatRate: 5,
},
{
Price: decimal.NewFromFloat(25),
VatRate: 7,
},
}
productsLayout, err := products.MakeLayout(ps)
if err != nil {
panic(err)
}
someDecimalValue := decimal.NewFromFloat(55.55)
v := productsLayout.DistributeDecimal(someDecimalValue)
fmt.Printf("someDecimalValue distributed according to products VAT groups: \n\t%s\n", v)
// Output:
// someDecimalValue distributed according to products VAT groups:
// [5: 27.78, 7: 27.77]
}