|
|
|
|
|
by joekinley
3822 days ago
|
|
What is "unexpected" about floor(17.999999) to return 17 instead of 18? Maybe my assumptions are wrong, and this is a truly curious question. I would ALWAYS expect floor to "basically" return the number in front of the ".", however close it is to another number. If you want that, you should use round(). |
|
Numbers will end up slightly lower or higher than an expected value simply due to accuracy in calculations and minor differences in input.
For example, suppose we have two UI elements, one with a width of 80% and the other expressed as a factor as 0.8. Depending on how specifically these are parsed and processed this may result in slightly different values. For the user creating the UI however they'd expect the same result.
The epsilons I introduce into my floor/ceil code is meant to deal with these minor variations.