davedelong / DDMathParser

String → Number
MIT License
854 stars 153 forks source link

Evaluating double gives wrong value #161

Closed tirrorex closed 5 years ago

tirrorex commented 5 years ago

Might be related to #99

Evaluating : let value = String("2.4+1.2") let evaluationValue = try value.evaluate() print(evaluationValue)

gives an ouput of 3.5999999999999 instead of 3.6 @davedelong is this the same issue ?

davedelong commented 5 years ago

Yep. Floating point numbers can’t always give accurate representations of decimal values like this.

tirrorex commented 5 years ago

I ended up rounding the value after evaluating for anyone interested :)

tirrorex commented 5 years ago

Actually i could use some help on this. Rounding the value at 11digits does not fix the issue and using a bigger number for rounding result in wrong behaviour for a lot of cases related to doubles. Thoughts ?