Fixing Floating Point Error
- by HannesNZ
I have some code that gets the leading value (non-zero) of a Double using normal math instead of String Math...
For Example:
0.020 would return 2
3.12 would return 3
1000 should return 1
The code I have at the moment is:
LeadingValue := Trunc(ResultValue * Power(10, -(Floor(Log10(ResultValue)))))
However when ResultValue is 1000 then LeadingValue ends up as 0.
What can I do to fix this problem I'm assuming is being caused by floating point errors?
Thanks.