If you are noticing that your Shopify theme is displaying your prices incorrectly (usually they are off by one penny) it is likely due to an issue with how Javascript handles floats.
You can see this in action by checking the developer console, if you write 39.95 * 100
(something we do in order to display the price) you don’t get the expected 3995
, but 3995.0000000000005
. This in turn messes up other calculations, which results in the off-by-one-penny price.
A workaround is to make a code change in the assets/algolia_helpers.js.liquid
file on your theme. You can replace lines 7-9 with the following:
var formatPrice = function formatPrice(value) {
return algolia.formatMoney(Math.floor(Number(value) * 100));
};
This will force JavaScript to drop the .000000000005
, and in turn helps our extension provide the right price.