Welcome to Bank Ruptcy, and we want to hire you to fix our algorithm to exchange the stock options, because we have some weird behaviour.
This is our algorithm to exchange the stock options:
var stockOptionsCost = 10.70, paid = 20.80;
function calculateChange() {
return paid - stockOptionsCost;
}
function calculateAmountOfStockOptions () {
return paid / stockOptionsCost;
}
var amountStockOptions = calculateAmountOfStockOptions();
var yourChange = calculateChange();
1.94392523364486
__match_answer_and_solution__
10.100000000000001
__match_answer_and_solution__
Javascript has several problems operating with floating point, this is one of the causes that it should not be to operate with floats.
__match_answer_and_solution__
var stockOptionsCost = 10.70, paid = 20.80; function calculateChange() { return (paid - stockOptionsCost).toFixed(2); } function calculateAmountOfStockOptions () { return paid / stockOptionsCost; } var amountStockOptions = calculateAmountOfStockOptions(); var yourChange = calculateChange();
assert(yourChange == 10.10);