当前位置: 首页>>代码示例>>Golang>>正文


Golang Money.Div方法代码示例

本文整理汇总了Golang中github.com/jbowles/money.Money.Div方法的典型用法代码示例。如果您正苦于以下问题:Golang Money.Div方法的具体用法?Golang Money.Div怎么用?Golang Money.Div使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/jbowles/money.Money的用法示例。


在下文中一共展示了Money.Div方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestMoneyDiv

// check division is good but also that original values are not modified
func TestMoneyDiv(t *testing.T) {
	m1 := money.Money{M: 67}   //67 cents!!
	m2 := money.Money{M: 6700} // 67 dollars
	res := m2.Div(&m1)
	finResi := int64(10000)
	finResf := float64(100.00)

	if res.Valuei() != finResi {
		t.Error("expected '10000' got: ", res.Valuei())
	}

	if res.Valuef() != finResf {
		t.Error("expected '100.00' got: ", res.Valuef())
	}

	if m1.Valuei() != int64(67) {
		t.Error("expected '67' got: ", m1.Valuei())
	}

	if m2.Valuei() != int64(6700) {
		t.Error("expected '6700' got: ", m2.Valuei())
	}

	if m1.Valuef() != float64(0.67) {
		t.Error("expected '0.67' got: ", m1.Valuef())
	}

	if m2.Valuef() != float64(67.00) {
		t.Error("expected '67.00' got: ", m2.Valuef())
	}

	if res.StringD() != "100.00" {
		t.Error("expected '100.00' got: ", res.StringD())
	}
}
开发者ID:zuzmic,项目名称:money,代码行数:36,代码来源:money_basic_ops_test.go

示例2: TestMoneyDivLargeDenom

// division with a large denominator
func TestMoneyDivLargeDenom(t *testing.T) {
	m1 := money.Money{M: 67}   //67 cents!!
	m2 := money.Money{M: 6700} // 67 dollars
	res := m1.Div(&m2)
	finResi := int64(1)
	finResf := float64(0.01)

	if res.Valuei() != finResi {
		t.Error("expected '1' got: ", res.Valuei())
	}

	if res.Valuef() != finResf {
		t.Error("expected '0.01' got: ", res.Valuef())
	}

	if res.StringD() != "0.01" {
		t.Error("expected '100' got: ", res.StringD())
	}
}
开发者ID:zuzmic,项目名称:money,代码行数:20,代码来源:money_basic_ops_test.go

示例3: 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())
	}
}
开发者ID:zuzmic,项目名称:money,代码行数:35,代码来源:money_basic_ops_test.go


注:本文中的github.com/jbowles/money.Money.Div方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。