• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang money.Money类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/corestoreio/csfw/storage/money.Money的典型用法代码示例。如果您正苦于以下问题:Golang Money类的具体用法?Golang Money怎么用?Golang Money使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: TestJSONUnMarshalSingle

func TestJSONUnMarshalSingle(t *testing.T) {
	tests := []struct {
		haveEnc  money.Encoder
		jsonData []byte
		want     string
		wantErr  error
	}{
		{money.JSONNumber, []byte{0xf1, 0x32, 0xd8, 0x8a, 0x12, 0x8a, 0x74, 0x2a, 0x5, 0x5d, 0x18, 0x39, 0xf9, 0xd7, 0x99, 0x8b}, `NaN`, nil},

		{money.JSONNumber, []byte(`1999.0000`), `1999.0000`, nil},
		{money.JSONNumber, []byte(`-0.01`), `-0.0100`, nil},
		{money.JSONNumber, []byte(`null`), `NaN`, nil},
		{money.JSONNumber, []byte(`1234.56789`), `1234.5679`, nil},
		{money.JSONNumber, []byte(`-1234.56789`), `-1234.5679`, nil},
		{money.JSONNumber, []byte(`2999x.0156`), `2999.0156`, nil},
		{money.JSONNumber, []byte(`""`), `NaN`, nil},

		{money.JSONLocale, []byte(`$ 999.00 `), `999.0000`, nil},
		{money.JSONLocale, []byte(`EUR 999.00`), `999.0000`, nil},
		{money.JSONLocale, []byte(`EUR 99x9.0'0`), `999.0000`, nil},
		{money.JSONLocale, []byte("EUR \x00 99x9.0'0"), `999.0000`, nil},
		{money.JSONLocale, []byte(`2 345 678,45 €`), `2345678.4500`, nil},
		{money.JSONLocale, []byte(`2 345 367,834456 €`), `2345367.8345`, nil},
		{money.JSONLocale, []byte(`null`), `NaN`, nil},
		{money.JSONLocale, []byte(`1.705,99 €`), `1705.9900`, nil},
		{money.JSONLocale, []byte(`705,99 €`), `705.9900`, nil},
		{money.JSONLocale, []byte(`$ 5,123,705.94`), `5123705.9400`, nil},
		{money.JSONLocale, []byte(`$ -6,705.99`), `-6705.9900`, nil},
		{money.JSONLocale, []byte(`$ 705.99`), `705.9900`, nil},
		{money.JSONLocale, []byte(`$ 70789`), `70789.0000`, nil},

		{money.JSONExtended, []byte(`[999.0000,"$","$ 999.00"]`), `999.0000`, nil},
		{money.JSONExtended, []byte(`[999.0000,null,null]`), `999.0000`, nil},
		{money.JSONExtended, []byte(`[1,999.00236,null,null]`), `1.0000`, nil},
		{money.JSONExtended, []byte(`[1999.00236,null,null]`), `1999.0024`, nil},
		{money.JSONExtended, []byte(`null`), `NaN`, nil},
		{money.JSONExtended, []byte(`[null,"$",null]`), `NaN`, nil},
		{money.JSONExtended, []byte(`[null,null,null]`), `NaN`, nil},
		{money.JSONExtended, []byte(`[ ]`), `NaN`, money.ErrDecodeMissingColon},
	}
	for _, test := range tests {
		var c money.Money
		err := c.UnmarshalJSON(test.jsonData)

		if test.wantErr != nil {
			assert.Error(t, err)
			assert.EqualError(t, err, test.wantErr.Error())
		} else {
			var buf []byte
			assert.NoError(t, err)
			buf = c.FtoaAppend(buf)
			have := string(buf)
			if test.want != have {
				t.Errorf("\nHave: %s\n\nWant: %s\n", have, test.want)
			}

		}
	}
}
开发者ID:levcom,项目名称:csfw,代码行数:59,代码来源:encoding_test.go


示例2: benchmark_JSONUnMarshalSingle

func benchmark_JSONUnMarshalSingle(b *testing.B, data []byte, want int64) {
	b.ReportAllocs()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		var c money.Money
		if err := c.UnmarshalJSON(data); err != nil {
			b.Error(err)
		}
		benchmark_JSONUnMarshalSingleValue = c.Raw()
		if benchmark_JSONUnMarshalSingleValue != want {
			b.Errorf("Have: %d\nWant: %d", benchmark_JSONUnMarshalSingleValue, want)
		}
	}
}
开发者ID:levcom,项目名称:csfw,代码行数:14,代码来源:encoding_bm_test.go


示例3: Benchmark_MoneyScan

// Benchmark_MoneyScan	 3000000	       504 ns/op	     136 B/op	       2 allocs/op => Go 1.4.2
// Benchmark_MoneyScan 	 5000000	       386 ns/op	     144 B/op	       2 allocs/op => Go 1.5.0
func Benchmark_MoneyScan(b *testing.B) {
	var d interface{}
	d = []byte{0x37, 0x30, 0x35, 0x2e, 0x39, 0x39, 0x33, 0x33}
	var want float64 = 705.993300
	b.ReportAllocs()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		var c money.Money
		c.Scan(d)
		benchmarkMoneyScan = c.Getf()
		if benchmarkMoneyScan != want {
			b.Errorf("Have: %f\nWant: %f", benchmarkMoneyScan, want)
		}
	}
}
开发者ID:levcom,项目名称:csfw,代码行数:17,代码来源:encoding_bm_test.go


示例4: TestScan

func TestScan(t *testing.T) {

	tests := []struct {
		src     interface{}
		want    string
		wantErr error
	}{
		{nil, `NaN`, nil},
		{[]byte{0x39, 0x39, 0x39, 0x2e, 0x30, 0x30, 0x30, 0x30}, `999.0000`, nil},
		{[]byte{0x37, 0x30, 0x35, 0x2e, 0x39, 0x39, 0x33, 0x33}, `705.9933`, nil},
		{[]byte{0x37, 0x30, 0x35, 0x2e, 0x39, 0x39, 0x33, 0x33}, `705.9933`, nil},
		{[]byte{0x37, 0x30, 0x35, 0x2e, 0x39, 0x39, 0x33, 0x33}, `705.9933`, nil},
		{[]byte{0x37, 0x30, 0x35, 0x2e, 0x39, 0x39, 0x33, 0x33}, `705.9933`, nil},
		{[]byte{0x37, 0x30, 0x35, 0x2e, 0x19, 0x39, 0x33, 0x13}, `0.0000`, strconv.ErrSyntax},
		{[]byte{0x37, 0x33}, `73.0000`, nil},
		{[]byte{0x37, 0x38}, `78.0000`, nil},
		{[]byte{0x37, 0x34}, `74.0000`, nil},
		{[]byte{0x37, 0x37}, `77.0000`, nil},
		{[]byte{0xa7, 0x3e}, `0.0000`, strconv.ErrSyntax},
		{int(33), `0.0000`, errors.New("Unsupported Type int for value. Supported: []byte")},
	}

	var buf bytes.Buffer
	for _, test := range tests {
		var c money.Money
		err := c.Scan(test.src)
		c.FmtCur = testFmtCur
		c.FmtNum = testFmtNum

		if test.wantErr != nil {
			assert.Error(t, err, "%v", test)
			assert.Contains(t, err.Error(), test.wantErr.Error())
		} else {
			assert.NoError(t, err, "%v", test)
			assert.EqualValues(t, test.want, string(c.Ftoa()), "%v", test)

			if _, err := c.NumberWriter(&buf); err != nil {
				t.Error(err)
			}
			buf.WriteString("; ")
		}
	}

	want := `NaN; 999.000; 705.993; 705.993; 705.993; 705.993; 73.000; 78.000; 74.000; 77.000; `
	have := buf.String()
	if want != have {
		t.Errorf("\nHave: %s\n\nWant: %s\n", have, want)
	}
}
开发者ID:levcom,项目名称:csfw,代码行数:49,代码来源:encoding_test.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang store.NewGroup函数代码示例发布时间:2022-05-23
下一篇:
Golang money.Currency类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap