yjp 1 жил өмнө
parent
commit
bcb330c59f
2 өөрчлөгдсөн 18 нэмэгдсэн , 0 устгасан
  1. 7 0
      money/money.go
  2. 11 0
      money/money_test.go

+ 7 - 0
money/money.go

@@ -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()
+}

+ 11 - 0
money/money_test.go

@@ -0,0 +1,11 @@
+package money
+
+import (
+	"testing"
+)
+
+func TestYuan2Fen(t *testing.T) {
+	if int(Yuan2Fen(1.2)) != 120 {
+		t.Fatal("元转换为分错误")
+	}
+}