Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
If you can truncate (get the floor() of a number), then you can round the number by adding 0.5 first. Or, I suppose that, for the sake of completeness, you add "the equivalent of 0.5," since a giv...
#1: Initial revision
If you can truncate (get the `floor()` of a number), then you can round the number by adding 0.5 first. Or, I suppose that, for the sake of completeness, you add "the equivalent of 0.5," since a given program might not represent the values in decimal or you might want to round to a non-ones position in the number. When you round numbers (and you know this, otherwise you wouldn't make the distinction, but to explain beyond "add a half"), a (decimal) digit of five or higher bumps the next-most-significant place up by one, otherwise you round. Assuming rounding to the nearest integer, then, from 0.0 to 0.49̅, adding 0.5 increases to 0.5 to 0.99̅, so truncation goes to the lower value. Anything higher crosses the threshold to the next integer, so truncation gives you that higher value.
