@@ -0,0 +1,7 @@
+package money
+
+import "github.com/shopspring/decimal"
+func Yuan2Fen(price float64) int64 {
+ return decimal.NewFromFloat(price).Mul(decimal.New(1, 2)).IntPart()
+}
@@ -0,0 +1,11 @@
+import (
+ "testing"
+)
+func TestYuan2Fen(t *testing.T) {
+ if int(Yuan2Fen(1.2)) != 120 {
+ t.Fatal("元转换为分错误")
+ }