Sfoglia il codice sorgente

添加钱的转换函数

yjp 1 anno fa
parent
commit
bcb330c59f
2 ha cambiato i file con 18 aggiunte e 0 eliminazioni
  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("元转换为分错误")
+	}
+}