@[toc]
科学计数法转换为小数点
工具类
func ScientificNotationTransform(numStr string) string { decimalNum, err := decimal.NewFromString(numStr) decimalNum = decimalNum.Abs() if err != nil { logrus.Errorf("decimal.NewFromString error, numStr:%s, err:%v", numStr, err) return numStr } return decimalNum.String() }
测试
func TestScientificNotationTransform(t *testing.T) { var str = "7.814E-7" s := ScientificNotationTransform(str) assert.Equal(t, s, "0.0000007814") str = "-12E-7" rs := ScientificNotationTransform(str) assert.Equal(t, rs, "0.0000012") }
原地址: https://blog.csdn.net/qq_40374604/category_11938137.html