Skip to content
This repository was archived by the owner on Oct 20, 2025. It is now read-only.

Conversation

@veqryn
Copy link
Contributor

@veqryn veqryn commented Nov 9, 2024

Right now, Decimal only has a Float64 method and an unused toString(), which returns just the data type.

The Float64 method is great, but like all floats, it can introduce errors because of how floats work.

Example:

	// This outputs: 0.008216620000000001
	// It should be: 0.00821662
	fmt.Println((&duckdb.Decimal{
		Width: 18,
		Scale: 8,
		Value: big.NewInt(821662),
	}).Float64())

This PR adds a Stinger method allowing a lossless and correct conversion from Decimal to a string.

@taniabogatsch
Copy link
Collaborator

Hi @veqryn, thanks for your PR! I only had two nits - then it should be good to go. :)

@taniabogatsch taniabogatsch added the feature / enhancement Code improvements or a new feature label Nov 11, 2024
@veqryn
Copy link
Contributor Author

veqryn commented Nov 11, 2024

Thank you @taniabogatsch , should be good now

@taniabogatsch
Copy link
Collaborator

Thanks!

@taniabogatsch taniabogatsch merged commit a559a1b into marcboeker:main Nov 12, 2024
@veqryn veqryn deleted the veqryn/decimal branch November 12, 2024 19:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

feature / enhancement Code improvements or a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants