First you need to convert input prices from strings to numbers. Then subtract. And you will have to convert the result back to the format "DKK ###, ##". These two functions should help.
var priceAsFloat = function (price) { return parseFloat(price.replace(/\./g, '').replace(/,/g,'.').replace(/[^\d\.]/g,'')); } var formatPrice = function (price) { return 'DKK ' + price.toString().replace(/\./g,','); }
Then you can do this:
var productBeforePrice = "DKK 399,95"; var productCurrentPrice = "DKK 299,95"; productPriceDiff = formatPrice(priceAsFloat(productBeforePrice) - priceAsFloat(productCurrentPrice));
source share