What's the best way to represent float64 as non-e-notation?

polaris · · 470 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I have a JSON that I don&#39;t necessarily know the structure, when unmarshaling it to <code>map[string]interface{}</code>, all numbers have <code>float64</code> type.</p> <p>Creating the perfect struct to map the values is difficult since I don&#39;t have control over the JSON and this API may change without notice.</p> <p>Many of my values are actually <code>int64</code>, but since they became <code>float64</code> when I print on <code>html/template</code>, they look like this: 3.486912512e+09</p> <p>What&#39;s the best way to represent that number as 3486912512?</p> <hr/>**评论:**<br/><br/>GopherFromHell: <pre><p>you can use a json.Decoder and call the function Decoder.UseNumber() that will unmarshal to a json.Number instead of float64</p> <p><a href="https://golang.org/pkg/encoding/json/#NewDecoder" rel="nofollow">https://golang.org/pkg/encoding/json/#NewDecoder</a> <a href="https://golang.org/pkg/encoding/json/#Decoder.UseNumber" rel="nofollow">https://golang.org/pkg/encoding/json/#Decoder.UseNumber</a> <a href="https://golang.org/pkg/encoding/json/#Number" rel="nofollow">https://golang.org/pkg/encoding/json/#Number</a></p></pre>pinpinbo: <pre><p>Ah, that&#39;s it. Thanks!</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

470 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传