Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem that the int64 type field returned by Go is beyond the range of javascript Number?

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article Xiaobian introduces in detail for you "Go returns int64 type field how to solve the javascript Number range", the content is detailed, the steps are clear, and the details are handled properly. I hope this "Go return int64 type field how to solve the javascript Number" article can help you solve your doubts, following the editor's ideas slowly in depth, together to learn new knowledge.

Problem description

The json returned by the Go service is in the following format, where deviceId_O is: 144115188584281742

And the deviceId_O that the front end gets becomes: 144115188584281730. The last two digits changed, resulting in unsuccessful debugging no matter how much you debug.

In fact, this problem is not difficult to locate, you only need to check the difference between Preview and Response in the debugging tools to compare it, but it will be weird when you encounter this problem for the first time.

Javascript Number maximum

The Number object provided by Javascript provides a MAX_SAFE_INTEGER, which is a fixed value: 9007199254740991. So why is it not safe beyond this range? Look at the example:

Go Int64 maximum

We use this code to get the maximum value of int64, which is 9223372036854775807.

I64: = int64 (^ uint (0) > > 1) fmt.Println (i64)

Solution

This problem can be solved by returning a value as a string when the Go service returns json. For example, the deviceId in the first figure in this article can be returned.

After reading this, the article "how to solve the problem that Go returns int64 type field beyond the scope of javascript Number" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it. If you want to know more about the article, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report