spyderwebceo21 Posted September 16, 2011 Posted September 16, 2011 We had pti write a global rule for one of our templates and we need it tweaked to include when our client has a price like this 3.49-4.49 function myPrice(price) { var trimPrice = ReplaceSubstring(ReplaceSubstring(price,'$',''),',',''); var decimalPrice = FormatNumber("0.00", trimPrice); var SuperPrice = Right(decimalPrice, 3); var NormalPrice = Left(decimalPrice, decimalPrice.length-3); var CentPrice = Right(decimalPrice, 2); var patt=/\d+/; var result = patt.test(price); if (result == false) { var newPrice = price; } else if (result == true) { if (price.indexOf("/") > -1 || price.indexOf("%") > -1) { var newPrice = ReplaceSubstring(price, "$", "<superscript>$</superscript>"); } else { if (StringToNumber(decimalPrice) >= 1) { if (price != "" && price.indexOf("$") < 0) { var newPrice = NormalPrice+"<superscript>"+SuperPrice+"</superscript>"; } else if (price != "" && price.indexOf("$") > -1) { var newPrice = "<superscript>$</superscript>"+NormalPrice+"<superscript>"+SuperPrice+"</superscript>"; } else if (price == "") { var newPrice = ""; } } else if (StringToNumber(decimalPrice) < 1) { if (price != "") { var newPrice = CentPrice+"<superscript>¢</superscript>"; } else if (price == "") { var newPrice = ""; } } } } return newPrice; }
Dan Korn Posted September 20, 2011 Posted September 20, 2011 Add this function after the other global one and call it instead: function myPrices(prices) { return String(prices).replace(/(\d+\.*\d+)/g, function(p){return myPrice(p)}); }
Recommended Posts
Archived
This topic is now archived and is closed to further replies.