本文整理汇总了Golang中github.com/jbowles/money.Money.Updatef方法的典型用法代码示例。如果您正苦于以下问题:Golang Money.Updatef方法的具体用法?Golang Money.Updatef怎么用?Golang Money.Updatef使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jbowles/money.Money
的用法示例。
在下文中一共展示了Money.Updatef方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestMoneyDivByZero
func TestMoneyDivByZero(t *testing.T) {
m1 := money.Money{}
m2 := money.Money{M: int64(1)}
m3 := money.Money{M: int64(72684839824903281)}
m4 := money.Money{}
m4.Updatef(float64(478326437489327489327838462381))
res1 := m2.Div(&m1)
res2 := m3.Div(&m1)
res3 := m4.Div(&m1)
if res1.Valuei() != int64(-9223372036854775807) {
t.Error("expected '-9223372036854775807' got: ", res1.Valuei())
}
if res2.Valuei() != int64(-9223372036854775807) {
t.Error("expected '-9223372036854775807' got: ", res2.Valuei())
}
if res3.Valuei() != int64(9223372036854775807) {
t.Error("expected '9223372036854775807' got: ", res3.Valuei())
}
if res1.Valuef() != float64(-9.223372036854776e+16) {
t.Error("expected '-9223372036854775807' got: ", res1.Valuef())
}
if res2.Valuef() != float64(-9.223372036854776e+16) {
t.Error("expected '-9223372036854775807' got: ", res2.Valuef())
}
if res3.Valuef() != float64(9.223372036854776e+16) {
t.Error("expected '9223372036854775807' got: ", res3.Valuef())
}
}
示例2: TestMoneyAddLarge
// adding large numbers floats via an `Updatef`
func TestMoneyAddLarge(t *testing.T) {
var val1 float64 = 12390678659.32 //12390678659.32
var val2 float64 = 8937670084.36 // 8937670084.36
m1 := money.Money{}
m2 := money.Money{}
m1Set := m1.Updatef(val1)
m2Set := m2.Updatef(val2)
res := m1Set.Add(m2Set)
//12390678659.32 + 8937670084.36 = 21,328,348,743.68
if res.Valuef() != float64(21328348743.68) {
t.Error("expected negaitve '21328348743.68' got: ", res.Valuef())
}
if res.Valuei() != int64(2132834874368) {
t.Error("expected negaitve '2132834874368' got: ", res.Valuei())
}
if res.StringD() != "21328348743.68" {
t.Error("expected '21328348743.68' got: ", res.StringD())
}
//12390678659.32 + 8937670084.36 = 21,328,348,743.68
if res.StringC() != "21328348743,68" {
t.Error("expected '21328348743,68' got: ", res.StringC())
}
}
示例3: TestMoneyAbs
func TestMoneyAbs(t *testing.T) {
v1 := int64(7839)
v2 := float64(38261748.09)
m1 := money.Money{M: -v1}
m2 := money.Money{}
m2.Updatef(-v2)
m1abs := m1.Abs()
m2abs := m2.Abs()
m1pos := money.Money{M: v1}
m2pos := money.Money{}
m2pos.Updatef(v2)
if m1abs.Valuei() != m1pos.Valuei() {
t.Error("expected '7839' got: ", m1abs.Valuei())
}
if m2abs.Valuei() != m2pos.Valuei() {
t.Error("expected '3826174809' got: ", m2abs.Valuei())
}
if m1.Abs().Valuei() != m1pos.Valuei() {
t.Error("expected '7839' got: ", m1.Abs().Valuei())
}
if m2.Abs().Valuei() != m2pos.Valuei() {
t.Error("expected '3826174809' got:", m2.Abs().Valuei())
}
//verify original values are still negative
if m1.Valuei() != -m1pos.Valuei() {
t.Error("expected '-7839' got: ", m1.Valuei())
}
if m2.Valuei() != -m2pos.Valuei() {
t.Error("expected '-3826174809' got: ", m2.Valuei())
}
}