-
Notifications
You must be signed in to change notification settings - Fork 26
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
Fractional values are defaulting to Decimal data type #22
Comments
Actually, after more investigation, the issue are the constants. The constants all seem to be decimals. So these work But this will not work in fact, this doesn't even work Am I missing something really simply to prevent fractional constants from being decimals and messing everything up? |
Hi @DigitalPigeon, Thanks for the bug report, you have found a certain issue. I have created the following unit test that confirms the issue you are seeing.
To hopefully explain the cause of the issue, currently when parsing a number with a decimal point Expressive assumes that the Furthermore there is an issue where the code actually goes about performing the multiplication. It should convert the two participants to a common type and perform the multiplication. The code was originally written to match the .NET world so if you try multiplying Unfortunately I am not quite in a position to publish a new version to fix this in the short term as I will be away until the start of June. When I am back I plan to do a release with support .NET Standard and I can wrap up this fix with it. A short term workaround can be to make sure that the constant appears on the left hand side of the multiplication. So where Sorry for the lengthy for response but I hope it helps. Shaun |
Okay - After downloading the code, the "culprit" seems to be in ExpressionParser.cs line 346. When you are detecting the data type of a constant, your order of preference is So in fact almost all fractional constants will be decimals. I think my only option here is to change the Numbers.cs file to support operations between Decimal and other types. I won't bother sending you a PR with the change, as you mentioned in #8 that you want to keep the behavior matching .net - but without casting or converting, it really limits usability for me. |
Shaun, Yup, seems like the same conclusion. And I did see your initial Convert.ToDecimal() changes in the Numbers.cs file. I've gone through and changed the rest, and it seems to be working for me now in my particular test cases. Thanks for looking at this so quickly! Wow! 👍 |
@DigitalPigeon it is good to hear that those changes are holding up well enough for now. I am planning on making a release in mid June that will incorporate the fixes for you but do feel free to send in the PR if you want. No problem on the response you managed to catch me at a good time :). I do wonder if #20 will also allow the explicit entry of a |
…type to correct division of double / decimal, etc.
@DigitalPigeon sorry I didn't give you an update to inform you that the latest release should resolve your issue. I hope it does. |
You are a rockstar @bijington . Thank you very much! |
It seems that the built in functions all return Decimals?
So when I run a formula like this
([myFirstDouble]/([mySecondDouble]*9.8))*3.14*POW([myThirdDouble],2)
I will always get this error:
Operator '*' can't be applied to operands of types 'double' and 'decimal'
Does this mean that expressive is essentially not compatible with doubles as inputs when you use both functions and multiplication?
This might be related to #8
The text was updated successfully, but these errors were encountered: