Closed tzachshabtay closed 3 years ago
According to the GDA spec, an invalid string (like your example) results in NaN.
The result of attempting to convert a string which does not have the syntax of a numeric string is [0,qNaN].
While I agree that it would be better to return an error here for a syntactically invalid string, the goal of this library is to adhere to the GDA spec. Plus, changing this would be a backward-incompatible change.
If you want to determine why SetString
returned NaN, you can check for the ConversionSyntax
Condition which is set when the input is syntactically invalid.
I should update the docs, however, as they're not exactly clear.
@ericlagergren I'm ok with it returning a NaN, when I posted the issue it didn't return NaN though, it returned 4. I see now in the playground that it's fixed, it does return NaN, was there a recent change that fixed this? I can still reproduce this with the version used by SQLBoiler, I want to tell them to upgrade, do we know which version was this fixed in? Thanks.
I just fixed it last night. https://github.com/ericlagergren/decimal/commit/f12e1f0a991056e646bffdde424d81f365aca94a
@ericlagergren is there any official release for this? Last release is from 2019 afaict. Thanks.
@ericlagergren any plans for an official release? 🙏
repro here: https://play.golang.org/p/xLn3Ds6SFjf