本文整理汇总了Golang中math/big.Rat.RatString方法的典型用法代码示例。如果您正苦于以下问题:Golang Rat.RatString方法的具体用法?Golang Rat.RatString怎么用?Golang Rat.RatString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类math/big.Rat
的用法示例。
在下文中一共展示了Rat.RatString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: coinUnits
// coinUnits converts a siacoin amount to base units.
func coinUnits(amount string) (string, error) {
units := []string{"pS", "nS", "uS", "mS", "SC", "KS", "MS", "GS", "TS"}
for i, unit := range units {
if strings.HasSuffix(amount, unit) {
// scan into big.Rat
r, ok := new(big.Rat).SetString(strings.TrimSuffix(amount, unit))
if !ok {
return "", errors.New("malformed amount")
}
// convert units
exp := 24 + 3*(int64(i)-4)
mag := new(big.Int).Exp(big.NewInt(10), big.NewInt(exp), nil)
r.Mul(r, new(big.Rat).SetInt(mag))
// r must be an integer at this point
if !r.IsInt() {
return "", errors.New("non-integer number of hastings")
}
return r.RatString(), nil
}
}
// check for hastings separately
if strings.HasSuffix(amount, "H") {
return strings.TrimSuffix(amount, "H"), nil
}
return "", errors.New("amount is missing units; run 'wallet --help' for a list of units")
}
示例2: parseFilesize
// parseFilesize converts strings of form 10GB to a size in bytes. Fractional
// sizes are truncated at the byte size.
func parseFilesize(strSize string) (string, error) {
units := []struct {
suffix string
multiplier int64
}{
{"kb", 1e3},
{"mb", 1e6},
{"gb", 1e9},
{"tb", 1e12},
{"kib", 1 << 10},
{"mib", 1 << 20},
{"gib", 1 << 30},
{"tib", 1 << 40},
{"b", 1}, // must be after others else it'll match on them all
{"", 1}, // no suffix is still a valid suffix
}
strSize = strings.ToLower(strSize)
for _, unit := range units {
if strings.HasSuffix(strSize, unit.suffix) {
r, ok := new(big.Rat).SetString(strings.TrimSuffix(strSize, unit.suffix))
if !ok {
return "", errUnableToParseSize
}
r.Mul(r, new(big.Rat).SetInt(big.NewInt(unit.multiplier)))
if !r.IsInt() {
f, _ := r.Float64()
return fmt.Sprintf("%d", int64(f)), nil
}
return r.RatString(), nil
}
}
return "", errUnableToParseSize
}
示例3: String
// String creates string of big.Rat. This is output format of calc.
func String(r *big.Rat) string {
return r.RatString()
}
示例4: OrderUploadHandler
// 上传订单
func OrderUploadHandler(c *gin.Context) {
//销售不允许上传
auth := userauth.Auth(c)
if auth.IsRole(bean.ROLE_SALES) {
c.HTML(http.StatusOK, "order_upload.tmpl", gin.H{"successCount": 0, "isUpload": true, "errMsg": "您没有权限"})
return
}
request := c.Request
request.ParseMultipartForm(2 << 10)
file, fileHeader, err := request.FormFile("file")
if err != nil {
Logger.Error("upload file error, %v", err)
panic(err)
}
_ = fileHeader
csvReader := csv.NewReader(file)
sql := insertSQL
values := make([]interface{}, 0, 40)
_, err = csvReader.Read()
if err != nil {
panic(err)
} else if err == io.EOF {
Logger.Debug("read file end")
return
}
rowsCount := 0
for {
if row, err := csvReader.Read(); err != nil && err == io.EOF {
break
} else if err != io.EOF {
rowsCount++
// 49 params 47 ?
sql += `(?, now(), now(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ),`
values = append(values, uuid.New())
r := new(big.Rat)
r.SetString(row[0])
values = append(values, r.RatString())
values = append(values, appendValues(row, 1, 12)...)
Logger.Debug("address: %v", row[13])
address := strings.Fields(row[13]) //dizhi
Logger.Debug("address args len:%v", len(address))
if len(address) == 4 {
values = append(values, address[0])
values = append(values, address[1])
values = append(values, address[2])
values = append(values, address[3])
for i := 0; i < 3; i++ {
values = append(values, nil)
}
} else {
for i := 0; i < 7; i++ {
values = append(values, nil)
}
}
values = append(values, appendValues(row, 14, 15)...)
runes := []rune(row[16])
if strings.HasPrefix(row[16], "'") {
runes = runes[1:]
}
values = append(values, string(runes))
values = append(values, appendValues(row, 17, 28)...)
runes = []rune(row[29])
if strings.HasSuffix(row[29], "元") {
runes = runes[:len(runes)-1]
}
buyerServiceFee, err := strconv.Atoi(string(runes))
if err != nil {
buyerServiceFee = 0
}
values = append(values, buyerServiceFee)
values = append(values, appendValues(row, 30, 32)...)
address = strings.Fields(row[35]) //dizhirow[36] //fixed dizhi
Logger.Debug("fixed address: %v", row[35])
Logger.Debug("fixed address args len:%v", len(address))
// 7
if len(address) == 4 {
values = append(values, address[0])
values = append(values, address[1])
values = append(values, address[2])
values = append(values, address[3])
for i := 0; i < 3; i++ {
values = append(values, nil)
}
} else {
for i := 0; i < 7; i++ {
//.........这里部分代码省略.........