Hacker News new | ask | show | jobs
by dragonwriter 3130 days ago
Sure they will. To truncated whole percents, (N2-N1)×100÷N1, using integer ops, gets you that, to whole percents rounded half up, ((N2-N1)×100+50)÷N1 does it. For additional decimal places, increase the fixed multiplier (and added factor for round-half-up) by the appropriate power of 10.

Even if you are dealing in units of hundreds of billions of dollars tracked to mils, this gets you up to, I think, a hundred-thousandth of a percent with int64.

1 comments

But with floats you just use a divide operation.
“Won’t cut it” and “will require 1-2 more operations” are very much not the same thing.