jwaliszko / ExpressiveAnnotations

Annotation-based conditional validation library.
MIT License
351 stars 123 forks source link

AssertThat with mathematical formulas ignores decimal places #206

Open tempel3 opened 4 years ago

tempel3 commented 4 years ago

Hi,

just in case someone experiences issues with decimal numbers while using AsserThat.

I have found an interessting behaviour of the used parser when using mixed type values in a mathematical formula.

When mixing int/decimal? the calculation returns a wrong result: Parser.Parse<double>(validationContextType, "MyValue * 4300").Invoke(new MyClass(){ MyValue = 1.2 }) == 4300 // should be 5160

Replacing the int by a number with a decimal place, the parser works as expected. Parser.Parse<double>(validationContextType, "MyValue * 4300.0").Invoke(new MyClass(){ MyValue = 1.2 }) == 5160

For constants just add ".0" [AssertThat("Value1<= Value2 * 4380.0",..)]

I hope this helps someone.