HACKER Q&A
📣 amichail

How do you pick numerical constants while programming?


Do you have a set of rules for doing this when the precise value of a number constant doesn't matter?

For example, would you use 0.875 or 0.9 in your code?


  👤 ksaj Accepted Answer ✓
It depends on tolerance. In electronics you allow for tolerance (+/- 5%). In carpentry you allow for tolerance (+/- 5mm). In cooking we allow for a huge tolerance (a pinch of salt! To Taste!) In delis, we allow for tolerance (ask for 100g of sliced ham, get more like 105g of sliced ham).

But when creating a small circle on a computer screen, we suddenly use a dozen decimal places where one or two (and sometimes no decimal place) would do.


👤 dave4420
How do you pick a number if someone asks you to pick a number, any number?

👤 mikequinlan
What are you using the number for?