Commit ef417273 by mushishixian

浮点数计算

parent 34399331
......@@ -9,10 +9,6 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"github.com/gogf/gf/util/gconv"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"go_sku_server/pkg/config"
"go_sku_server/pkg/vars"
"math"
......@@ -24,6 +20,12 @@ import (
"strconv"
"strings"
"time"
"github.com/gin-gonic/gin"
"github.com/gogf/gf/util/gconv"
"github.com/shopspring/decimal"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
)
/*
......@@ -601,3 +603,9 @@ func MyRound(x float64, wei int) float64 {
}
////////////类型转换/////////////////////
//浮点数乘法
func MulFloat(x float64, y float64) float64 {
result, _ := decimal.NewFromFloat(x).Mul(decimal.NewFromFloat(y)).Float64()
return result
}
......@@ -420,7 +420,6 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
if !hasCoefficient {
coefficient = defaultCoefficient
}
fmt.Println("供应商系数 : ", coefficient)
//下面是计算价格
......@@ -445,9 +444,13 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
}
}
//美金成本价
priceCostUs := common.MyRound(price.PriceUs*usDiscountRatio, 4)
priceCostUs := common.MulFloat(price.PriceUs, usDiscountRatio)
fmt.Println(priceCostUs)
priceCostUs = common.MyRound(priceCostUs, 4)
//美金售价
priceUs := priceCostUs * priceRatio.RatioUsd
priceUs := common.MulFloat(priceCostUs, priceRatio.RatioUsd)
// priceUs := priceCostUs * priceRatio.RatioUsd
fmt.Println(priceUs)
//人民币成本价
priceCostCn := common.MyRound(price.PriceUs*coefficient.Ratio*cnDiscountRatio*tax, 4)
//人民币售价
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment