3 ms·
I would have called the function "calculateTransferTax". It's shorter while providing the same meaning. Also, the "tax" argument is the tax _rate_. "tax" in t
by mtviewdave 11y ago
I would have called the function "calculateTransferTax". It's shorter while providing the same meaning.
Also, the "tax" argument is the tax _rate_. "tax" in this instance I would expect to mean the final amount. So I'd call that parameter "taxRate".
(And I'd use ints for everything, of course)
- thameera 11y agoHow would you use ints when there's division in the code? I've heard it's usually better to prefer ints to floating points, but in my limited experience I've found that it's easier said than done.
- JamesMcMinn 11y agoUsing floating point arithmetics for currency is just asking for trouble: http://stackoverflow.com/questions/3730019/why-not-use-double-or-float-to-represent-currency http://stackoverflow.com/questions/3730019/why-not-use-doubl...
- Intermernet 11y agoEither return cents (for decimal currencies), or more generally create a "currency" type with ints and conversion ratios for each "field" (for example a "US Dollar" type would have "dollars" and "cents", with ratios of "1" and "100". This means you can handle non-decimal currencies[1] like the Malagasy Ariary[2] and the Mauritanian Ouguiya[3] (1 ariary = 5 iraimbilanja, 1 ouguiya = 5 khoums) As you said, easier said than done; but you really don't want FP errors popping up in financial calculations :-) [1]: https://en.wikipedia.org/wiki/Non-decimal_currency https://en.wikipedia.org/wiki/Non-decimal_currency [2]: https://en.wikipedia.org/wiki/Malagasy_ariary https://en.wikipedia.org/wiki/Malagasy_ariary [3]: https://en.wikipedia.org/wiki/Mauritanian_ouguiya https://en.wikipedia.org/wiki/Mauritanian_ouguiya
- cremno 11y agoUse BigDecimal or whatever that kind of type is called in the used programming language. http://floating-point-gui.de/basic/ http://floating-point-gui.de/basic/ http://0.30000000000000004.com/ http://0.30000000000000004.com/