parent
8180321217
commit
40ba1daf69
2 changed files with 12 additions and 0 deletions
|
@ -89,6 +89,11 @@ func (a Amount) ToUnit(u AmountUnit) float64 {
|
|||
return float64(a) / math.Pow10(int(u+8))
|
||||
}
|
||||
|
||||
// ToBTC is the equivalent of calling ToUnit with AmountBTC.
|
||||
func (a Amount) ToBTC() float64 {
|
||||
return a.ToUnit(AmountBTC)
|
||||
}
|
||||
|
||||
// Format formats a monetary amount counted in bitcoin base units as a
|
||||
// string for a given unit. The conversion will succeed for any unit,
|
||||
// however, known units will be formated with an appended label describing
|
||||
|
|
|
@ -185,6 +185,13 @@ func TestAmountUnitConversions(t *testing.T) {
|
|||
continue
|
||||
}
|
||||
|
||||
// Verify that Amount.ToBTC works as advertised.
|
||||
f1 := test.amount.ToUnit(AmountBTC)
|
||||
f2 := test.amount.ToBTC()
|
||||
if f1 != f2 {
|
||||
t.Errorf("%v: ToBTC does not match ToUnit(AmountBTC): %v != %v", test.name, f1, f2)
|
||||
}
|
||||
|
||||
// Verify that Amount.String works as advertised.
|
||||
s1 := test.amount.Format(AmountBTC)
|
||||
s2 := test.amount.String()
|
||||
|
|
Loading…
Reference in a new issue