3 ms·
Well, that is why I called it an 'inverted fizz-buzz test'. The test itself reveals limitations in the organization doing the interviewing. While you may be ab
by dalke 11y ago
Well, that is why I called it an 'inverted fizz-buzz test'. The test itself reveals limitations in the organization doing the interviewing.
While you may be able to work in integer cents, there is still the question of how you handle rounding. Does Richard Pryor get your fractional cent, a la the salami slicing in Superman 3?
Banks typically work in five or six decimal places, and not the 2 decimals you can use. As a specific example, the final conversion rates from the national currencies to the Euro are given to 6 significant digits, eg, 1.95583 Deutsch marks to the Euro. Zimbabwe had problems when their hyperinflation caused overflows in systems that assumed 64 bit integers was enough for any currency.
I don't understand what you mean by "quirks in Python". Your concern seems to be with the General Decimal Arithmetic Specification, and not its implementation in Python.
- raverbashing 11y agoSure, rounding is important as well. > I don't understand what you mean by "quirks in Python" Setting a precision for decimal numbers "globally" in the module. https://docs.python.org/2/library/decimal.html https://docs.python.org/2/library/decimal.html But of course, working with cents might get complicated if you're doing a lot of calculations, people should use Decimal Then there was Django's Decimal field which wouldn't even do comparisons correctly and was filled with bugs (in 1.2 at least)
- dalke 11y agoMinor correction; the decimal context is thread-local, and not set '"globally" in the module'. It's similar in philosophy to C99's support for IEEE 754's rounding modes and exception modes. Compare to http://en.cppreference.com/w/c/numeric/fenv http://en.cppreference.com/w/c/numeric/fenv : > The floating-point environment is the set of floating-point status flags and control modes supported by the implementation. It is thread-local, each thread inherits the initial state of its floating-point environment from the parent thread. Since standard floats in C have similar behavior, it's hard for me to agree that it's really a "quirk".