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


Golang Money.Ftoa方法代码示例

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


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

示例1: 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.Ftoa方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。