First you need to convert the input prices from strings to numbers. Then subtract. And you'll have to convert the result back to "DKK ###,##" format. 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));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…