Jump to content

Tweak to JavaScript Global Rule


spyderwebceo21

Recommended Posts

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;

}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...