Problem with percentage discount on sale badge displaying correctly

Hi guys,

Hope someone who’s tech savvy can help me out. I’ve got some code implemented that shows the percentage % discount in stead of the text ‘sale’. But the decimals aren’t always working correctly.

Example:

Product X = 41,99

-30% = 29,393 → so 29,39

Then is doesn’t show -30% but something like -300714455822815%

When I change the price to 29,40 is says -30%. I’m using a bulk editor for discounts, so it’s not ideal when we have to change the prices manually when there is sale.

Also, when a product with differect sizes has different prices the discount percentage displaying is not correct and not logical at all.

Example:

https://plukandpaloma.com/products/sofia-slippers-give-a-pon

Sizes 21-34 are 39,95 - 30% = 27,965 (where I have to make it to 27,98 because of above problem)

Sizes 35-40 are 49,95 - 30% = 34,965 (where I have to make it to 34,98 because of above problem)

→ So it should show ‘-30%’ on the badge, but in stead it shows ‘-44%’. That is the percentage of the kids size original price matched with the adult size sale price. Weird right?

If someone good in math and code and likes a challenge can help me out, I would be so grateful!

Kindest,

Kelly