fix
This commit is contained in:
parent
2ac507ef34
commit
9e2526405f
|
@ -108,14 +108,17 @@ func (l *GetProductStepPriceLogic) GetProductStepPrice(req *types.GetProductStep
|
|||
for rIndex, rangeInfo := range stepPrice.PriceRange {
|
||||
//最后一个
|
||||
if rIndex+1 == rangeLen {
|
||||
begin := format.NumToStringWithThousandthPercentile(fmt.Sprintf("%d", rangeInfo.StartQuantity))
|
||||
stepRange = append(stepRange, map[string]interface{}{
|
||||
"range_description": fmt.Sprintf(">=%s Units", format.NumToStringWithThousandthPercentile(rangeInfo.StartQuantity)),
|
||||
"range_description": fmt.Sprintf(">=%s Units", begin),
|
||||
"item_price": format.CentitoDollar(rangeInfo.Price, 3),
|
||||
})
|
||||
break
|
||||
}
|
||||
begin := format.NumToStringWithThousandthPercentile(fmt.Sprintf("%d", rangeInfo.StartQuantity))
|
||||
end := format.NumToStringWithThousandthPercentile(fmt.Sprintf("%d", rangeInfo.EndQuantity))
|
||||
stepRange = append(stepRange, map[string]interface{}{
|
||||
"range_description": fmt.Sprintf("%s-%s Units", format.NumToStringWithThousandthPercentile(rangeInfo.StartQuantity), format.NumToStringWithThousandthPercentile(rangeInfo.EndQuantity)),
|
||||
"range_description": fmt.Sprintf("%s-%s Units", begin, end),
|
||||
"item_price": format.CentitoDollar(rangeInfo.Price, 3),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,18 +1,31 @@
|
|||
package format
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 数字变成带千分位的字符串
|
||||
func NumToStringWithThousandthPercentile(number int64) string {
|
||||
s := fmt.Sprintf("%d", number)
|
||||
func NumToStringWithThousandthPercentile(numberStr string) string {
|
||||
if _, err := strconv.ParseFloat(numberStr, 64); err != nil {
|
||||
log.Fatalln("is not a number")
|
||||
return ""
|
||||
}
|
||||
sliceList := strings.Split(numberStr, ".")
|
||||
s := sliceList[0]
|
||||
f := ""
|
||||
if len(sliceList) == 2 {
|
||||
f = "." + sliceList[1]
|
||||
}
|
||||
l := len(s)
|
||||
if l <= 3 {
|
||||
return s
|
||||
return s + f
|
||||
}
|
||||
r := l % 3 //前面第几位开始加入千分位
|
||||
if r == 0 {
|
||||
r = 3
|
||||
}
|
||||
b := strings.Builder{}
|
||||
for i := 0; i < l; i++ {
|
||||
b.WriteString(string(s[i]))
|
||||
|
@ -21,5 +34,6 @@ func NumToStringWithThousandthPercentile(number int64) string {
|
|||
r += 3
|
||||
}
|
||||
}
|
||||
b.WriteString(f)
|
||||
return b.String()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user