forked from wakiyamap/monautil
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
77 lines (63 loc) · 1.79 KB
/
example_test.go
File metadata and controls
77 lines (63 loc) · 1.79 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package monautil_test
import (
"fmt"
//"math"
"github.com/monasuite/monautil"
"github.com/shopspring/decimal"
)
func ExampleAmount() {
a := monautil.Amount(0)
fmt.Println("Zero Satoshi:", a)
a = monautil.Amount(1e8)
fmt.Println("100,000,000 Satoshis:", a)
a = monautil.Amount(1e5)
fmt.Println("100,000 Satoshis:", a)
// Output:
// Zero Satoshi: 0 MONA
// 100,000,000 Satoshis: 1 MONA
// 100,000 Satoshis: 0.001 MONA
}
func ExampleNewAmount() {
amountOne, err := monautil.NewAmount(decimal.NewFromFloat(1))
if err != nil {
fmt.Println(err)
return
}
fmt.Println(amountOne) //Output 1
amountFraction, err := monautil.NewAmount(decimal.NewFromFloat(0.01234567))
if err != nil {
fmt.Println(err)
return
}
fmt.Println(amountFraction) //Output 2
amountZero, err := monautil.NewAmount(decimal.NewFromFloat(0))
if err != nil {
fmt.Println(err)
return
}
fmt.Println(amountZero) //Output 3
amountNaN, err := monautil.NewAmount(decimal.NewFromFloat(1051200000000.00000001))
if err != nil {
fmt.Println(err)
return
}
fmt.Println(amountNaN) //Output 4
// Output: 1 MONA
// 0.01234567 MONA
// 0 MONA
// invalid monacoin amount
}
func ExampleAmount_unitConversions() {
amount := monautil.Amount(44433322211100)
fmt.Println("Satoshi to kBTC:", amount.Format(monautil.AmountKiloBTC))
fmt.Println("Satoshi to BTC:", amount)
fmt.Println("Satoshi to MilliBTC:", amount.Format(monautil.AmountMilliBTC))
fmt.Println("Satoshi to MicroBTC:", amount.Format(monautil.AmountMicroBTC))
fmt.Println("Satoshi to Satoshi:", amount.Format(monautil.AmountSatoshi))
// Output:
// Satoshi to kBTC: 444.333222111 kMONA
// Satoshi to BTC: 444333.222111 MONA
// Satoshi to MilliBTC: 444333222.111 mMONA
// Satoshi to MicroBTC: 444333222111 μMONA
// Satoshi to Satoshi: 44433322211100 Watanabe
}