-
Notifications
You must be signed in to change notification settings - Fork 556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DynamoDB attributevalue.Integer() loses precision for large values #186
Labels
Comments
This code can be used to confirm this behaviour: package main
import (
"fmt"
"strconv"
"time"
)
func main() {
base := time.Now().UnixNano()
baseString := strconv.FormatInt(base, 10)
floatParse, _ := strconv.ParseFloat(baseString, 64)
floatResult := int64(floatParse)
intResult, _ := strconv.ParseInt(baseString, 10, 64)
fmt.Println("origin: ", base)
fmt.Println("current behaviour: ", floatResult)
fmt.Println("proposed behaviour: ", intResult)
} Execution result:
|
joeke80215
added a commit
to joeke80215/aws-lambda-go
that referenced
this issue
Oct 13, 2019
bmoffatt
pushed a commit
that referenced
this issue
Oct 14, 2019
* fixed loses precision for large values #186 * update
Solved at #227. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When dealing with large integer values (timestamps in nanoseconds) that you are able to store in DynamoDB,
attributevalue.Integer()
will lose precision when converting to int64. An example value would be1556893286484340854
.This is caused by the
strconv.ParseFloat(value, 64)
LOC that this function uses before converting to int64. When doing astrconv.ParseInt(value, 10, 64)
instead, the value does not lose precision.The text was updated successfully, but these errors were encountered: