lbcutil/example_test.go
Mawuli Adzoe 7501aee141 Improve godocs. Add testable example for NewAmount
This is consistent with the rest of the code base.
i.e.: base58/bloom/hash160/hdkeychain.
2015-07-21 03:50:16 +00:00

43 lines
679 B
Go

package btcutil_test
import (
"fmt"
"math"
. "github.com/btcsuite/btcutil"
)
func ExampleNewAmount() {
amountOne, err := NewAmount(1)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(amountOne) //Output 1
amountFraction, err := NewAmount(0.01234567)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(amountFraction) //Output 2
amountZero, err := NewAmount(0)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(amountZero) //Output 3
amountNaN, err := NewAmount(math.NaN())
if err != nil {
fmt.Println(err)
return
}
fmt.Println(amountNaN) //Output 4
// Output: 1 BTC
// 0.01234567 BTC
// 0 BTC
// invalid bitcoin amount
}