简体   繁体   中英

How to convert float64 to json.Number golang

I have ,

  {"time": 14990, "timeTaken": 5.43420481682}

I want timeTaken as json.Number so I am trying this -

  {"time": 14990, "timeTaken": json.Number(5.43420481682)}

But it is not working.

json.Number is internally, a string. Using strconv.FormatFloat should work.

json.Number(strconv.FormatFloat(123.456, 'e', -1, 64))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM