当前位置:网站首页>golang json unsupported value: NaN 处理
golang json unsupported value: NaN 处理
2022-06-26 08:16:00 【用户昵称不能为空】
原因
golang 计算 math.Pow 导致数值变成了NaN
Python
使用Python计算没有这个问题
>>> sR = 100
>>> sV = -18.29
>>> pow(pow(1+sV/2,1/100),sR)
(-8.145000000000028+3.1086244689504383e-15j)
但使用GoLang 计算出来的结果是NaN
解决
var result float64
if fmt.Sprintf("%v",result) == "NaN" {
result = 0
}
或者
if math.IsNaN(result) {
result = 0
}
封装函数
func GetString(f float64, percent bool) (s string) {
if math.IsInf(f, 0) {
return "Inf"
}
if math.IsNaN(f) {
return "NaN"
}
suffix := ""
if percent {
f *= 100
suffix += "%"
}
s = fmt.Sprintf("%d%s", int(math.Round(f)), suffix)
return
}
边栏推荐
- [postgraduate entrance examination] group planning exercises: memory
- drf的相关知识
- SOC的多核启动流程详解
- Chapter 5 (array)
- JWT in go
- ReW_ p
- Software engineering - high cohesion and low coupling
- JS file message invalid character error
- Project practice: parameters of pycharm configuration for credit card digital recognition and how to use opencv in Anaconda
- Seven important reasons for responsive Web Design
猜你喜欢

Chapter VI (pointer)

1. error using XPath to locate tag

Quickly upload data sets and other files to Google colab ------ solve the problem of slow uploading colab files

Uploading pictures with FileReader object

The difference between push-pull circuit drive and totem pole drive

buuresevewp

StarWar armor combined with scanning target location

Detailed explanation of the generate go file command of import in golang (absolute detail)

Livevideostackcon | evolution of streaming media distribution for online education business

Chapter 4 (functions and preprocessing)
随机推荐
Diode voltage doubling circuit
h5 localStorage
Use intent to shuttle between activities -- use implicit intent
Reflection example of ads2020 simulation signal
Pic 10B parsing
Wechat applet beginner level chapter
JS precompile - Variable - scope - closure
Teach you a few tricks: 30 "overbearing" warm words to coax girls, don't look regret!
Power apps application practice | easily develop employee leave attendance management applet with power apps
[issue 22] sheen cloud platform one side & two sides
Seven important reasons for responsive Web Design
Test method - decision table learning
监听iPad键盘显示和隐藏事件
Solve the problem that pychar's terminal cannot enter the venv environment
The difference between setstoragesync and setstorage
[postgraduate entrance examination planning group] conversion between signed and unsigned numbers
MySQL insert Chinese error
Ping An technology's practice of migrating from Oracle to ubisql
Batch modify file name
Uni app installation and project directory (hbuilder configuration)