You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’ve encountered an issue when using c.ShouldBind() in the Gin framework. When binding JSON data to Go struct fields, numeric values that are too large or too small are automatically converted to scientific notation (e.g., 1.23e5 or 5.67e-3). This can lead to precision loss or formatting issues in certain cases.
Hi Every Body,
I’ve encountered an issue when using c.ShouldBind() in the Gin framework. When binding JSON data to Go struct fields, numeric values that are too large or too small are automatically converted to scientific notation (e.g., 1.23e5 or 5.67e-3). This can lead to precision loss or formatting issues in certain cases.
For example, the following JSON:
is being bound into a Go struct like this:
In the data field, the id value is interpreted as 1.23e5, which may not be the desired format in some use cases.
In Go, I’m aware that I can use the following solution to handle this issue:
This helps preserve the exact numeric value without converting it into scientific notation.
IN goframe:
My Question:
Does Gin provide a similar built-in functionality or method to prevent c.ShouldBind() from converting numbers to scientific notation?
Any insights or recommendations would be greatly appreciated.
Thanks in advance!
Best regards!
The text was updated successfully, but these errors were encountered: