Skip to content
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

Closed
BastiPaeltz opened this issue May 7, 2019 · 2 comments
Closed
Labels

Comments

@BastiPaeltz
Copy link

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 be 1556893286484340854.
This is caused by the strconv.ParseFloat(value, 64) LOC that this function uses before converting to int64. When doing a strconv.ParseInt(value, 10, 64) instead, the value does not lose precision.

@bmoffatt bmoffatt added the bug label May 9, 2019
joeke80215 added a commit to joeke80215/aws-lambda-go that referenced this issue Aug 29, 2019
@diegobernardes
Copy link
Contributor

diegobernardes commented Oct 10, 2019

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:

origin:              1570726625494837000
current behaviour:   1570726625494836992
proposed behaviour:  1570726625494837000

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
@diegobernardes
Copy link
Contributor

Solved at #227.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants