代码拉取完成,页面将自动刷新
package amountdecimal
import (
"encoding/json"
"errors"
"fmt"
)
func NewJsonNumber(amount json.Number) *AmountDecimal {
return NewString(amount.String())
}
// @title: addition json.Number type
// @auth: jishulang.com
// @date: 2022/7/30 20:59
func (c *AmountDecimal) AddJsonNumber(amounts ...json.Number) *AmountDecimal {
return c.amountsJsonNumber(add, amounts...)
}
// @title: subtraction json.Number type
// @auth: jishulang.com
// @date: 2022/7/30 20:59
func (c *AmountDecimal) SubJsonNumber(amounts ...json.Number) *AmountDecimal {
return c.amountsJsonNumber(sub, amounts...)
}
// @title: multiplication json.Number type
// @auth: jishulang.com
// @date: 2022/7/30 20:59
func (c *AmountDecimal) MulJsonNumber(amounts ...json.Number) *AmountDecimal {
return c.amountsJsonNumber(mul, amounts...)
}
// @title: division json.Number type
// @auth: jishulang.com
// @date: 2022/7/30 20:59
func (c *AmountDecimal) DivJsonNumber(amounts ...json.Number) *AmountDecimal {
return c.amountsJsonNumber(div, amounts...)
}
func (c *AmountDecimal) amountsJsonNumber(f uint8, amounts ...json.Number) *AmountDecimal {
if c.err != nil {
return c
}
if len(amounts) == 0 {
c.err = errors.New(errCodeMap[amounts_empty])
return c
}
var amounts2 []string
amountStr := ""
for _, amount := range amounts {
if f == div && amount == json.Number(0) {
c.err = errors.New(errCodeMap[amount_divisor_zero])
return c
}
amountStr = fmt.Sprintf("%v", amount)
amounts2 = append(amounts2, amountStr)
}
return c.amountsString(f, amounts2...)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。