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


Golang Dec.SetString方法代码示例

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


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

示例1: add

func (c Test) add(str1 string, str2 string) dec.Dec {
	dec1 := dec.Dec{}
	dec1.SetString(str1)
	dec2 := dec.Dec{}
	dec2.SetString(str2)

	result := dec.Dec{}
	result.Add(&dec1, &dec2)
	return result
}
开发者ID:hongjinqiu,项目名称:finance,代码行数:10,代码来源:test.go

示例2: Add

func (c MathUtil) Add(str1 string, str2 string) string {
	dec1 := dec.Dec{}
	dec1.SetString(str1)
	dec2 := dec.Dec{}
	dec2.SetString(str2)

	result := dec.Dec{}
	result.Add(&dec1, &dec2)
	return result.String()
}
开发者ID:hongjinqiu,项目名称:finance,代码行数:10,代码来源:MathUtil.go

示例3: Quo

/**
return x / y
*/
func (c MathUtil) Quo(str1 string, str2 string, scaler dec.Scaler, rounder dec.Rounder) string {
	dec1 := dec.Dec{}
	dec1.SetString(str1)
	dec2 := dec.Dec{}
	dec2.SetString(str2)

	result := dec.Dec{}
	result.Quo(&dec1, &dec2, scaler, rounder)
	return result.String()
}
开发者ID:hongjinqiu,项目名称:finance,代码行数:13,代码来源:MathUtil.go

示例4: NewFundraiserTransaction

func NewFundraiserTransaction(addr Address, value int64, time int64) (*FundraiserTransaction, error) {
	tx := &FundraiserTransaction{
		Addr: addr.Addr,
		Time: time,
	}

	// Base line amount bought from fundraiser, 1 btc gets you 100 msc
	mastercoinBought := dec.NewDecInt64((value * 100))
	mastercoinBought.Quo(mastercoinBought, dec.NewDecInt64(1e8), dec.Scale(18), dec.RoundHalfUp)

	fmt.Println("Baseline MSC Bought:", mastercoinBought)

	// Bonus amount received
	diff := dec.NewDecInt64(FundraiserEndTime - time)
	timeDifference := diff.Quo(diff, dec.NewDecInt64(604800), dec.Scale(18), dec.RoundHalfUp)

	fmt.Println("Time difference", timeDifference)

	if timeDifference.Cmp(dec.NewDecInt64(0)) > 0 {
		// bought += bought * (timediff * 0.1)

		x := new(dec.Dec)
		x.SetString("0.1")

		ratio := new(dec.Dec).Mul(timeDifference, x)
		fmt.Println("Ratio:", ratio)
		bonus := new(dec.Dec).Mul(ratio, mastercoinBought)
		bonus.Round(bonus, dec.Scale(18), dec.RoundDown)

		mastercoinBought.Add(mastercoinBought, bonus)
		mastercoinBought.Round(mastercoinBought, dec.Scale(8), dec.RoundHalfUp)
	}

	tx.Value = mastercoinBought

	Logger.Println("Created fundraiser transaction", tx)

	return tx, nil
}
开发者ID:Nevtep,项目名称:mscutil,代码行数:39,代码来源:transaction.go

示例5: getDec

func (c Test) getDec(str string) dec.Dec {
	result := dec.Dec{}
	result.SetString(str)
	return result
}
开发者ID:hongjinqiu,项目名称:finance,代码行数:5,代码来源:test.go

示例6: DecFromString

func DecFromString(input string) *dec.Dec {
	x := new(dec.Dec)
	x.SetString(input)
	return x
}
开发者ID:Nevtep,项目名称:mscutil,代码行数:5,代码来源:transaction_test.go


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