money.go 340 B

1234567891011121314
  1. package money
  2. import "github.com/shopspring/decimal"
  3. func Yuan2Fen(price float64) int64 {
  4. return decimal.NewFromFloat(price).Mul(decimal.New(1, 2)).IntPart()
  5. }
  6. func Fen2Yuan(price uint64) float64 {
  7. //分除以100得到元
  8. d := decimal.New(1, 2)
  9. result, _ := decimal.NewFromInt(int64(price)).DivRound(d, 2).Float64()
  10. return result
  11. }