douhe2305 2014-12-27 07:37
浏览 149
已采纳

golang大数字转换为可读/字符串格式

I have a json response from an API that look like this after I use json. Unmarshal then save it to an interface variable.

 map[message_num:3 
 task_num:0 
 name: test_room 
 type:my role:member sticky:true unread_num:0 
 room_id:3.190762e+06 ]

I want to get the room_id, but its not readable

 3.190762e+06

I want to format this to a string, so I can use it to send a post request.

  • 写回答

1条回答 默认 最新

  • duanbi3151 2014-12-27 07:46
    关注

    You could extract room_id from your JSON as a string "3.190762e+06".
    Then you can:

    See this example:

    i, err := strconv.ParseFloat("3.190762e+06", 64)
    if err == nil {
        s := fmt.Sprintf("%.0f
    ", i)
        fmt.Println(s)
    } 
    

    Output:

    3190762
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题