What's the best way to implement System.Decimal conversions? #2432
Unanswered
DaveSkender
asked this question in
Q&A
Replies: 1 comment 1 reply
|
I had a bit of a longer conversation with Chad. He's saying the only way to avoid using string conversion is to simply use the .NET decimal type in Python (not trying to convert to Python decimal); and if you really need to convert to Py decimal, want better conversion performance, and are okay with some loss in precision, then double hop through |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
the problem
In our Python wrapper of a .NET library, we've struggled along with our users with issues related to
localesettings and relatedSystem.Decimalconversions.decimal.InvalidOperationwith small numbers facioquo/stock-indicators-python#385We're fairly sure we simply don't understand the problem and potential solutions well enough, but have tried a few things that usually boil down to a rather expensive double conversion from a string value ... which smells really bad.
Aside from the overly complex need to wrangle with our own defensive code, we did expect to see some overhead costs when going back and forth between .NET and Python, but are seeing larger than expected performance loss, about 10x slower. I have a sneaking suspicion that this string conversion is the biggest contributor.
I see a few failed attempts for feature ideas and some comments about using existing codecs or some custom variants, but they seem to do the same double conversion through a string value. Even my conversation with ChatGPT seems to suggest it.
the question(s)
cc @LeeDongGeon1996
All reactions