Jump to content

% and $ rule


pbrown

Recommended Posts

I have a template where a customer can enter an amount off for a coupon. It can be a dollar amount or a percent. So I am trying to create a rule that will superscript the % if a percent amount is entered or superscript the $ and cents if a dollar amount is entered. I need one rule that does both and I am struggling creating it. Does anybody have such a rule? Thanks.
Link to comment
Share on other sites

Can you add a sample PDF showing the various formats you want to handle along with a data file to show how your data will be supplied?

 

If your field will contain either "1.99", ".99", or "20%", you could do something like:

var amount = Field(YOUR FIELD");
// convert cent-only values to ##¢ format
if (Left(amount,1) == ".") amount = Right(amount,2) + "¢";
// convert dollar values to $#.## format
else if (amount.indexOf("%") == -1) amount = "$" + amount;
// add superscripting for symbols
amount = amount.replace("$","<superscript>$</superscript>").replace("¢","<superscript>¢</superscript>").replace("%","<superscript>%</superscript>");
return amount;

Of course, this may not work if other values can be input (i.e. "$1.99", "$.99", "0.99", etc).

Link to comment
Share on other sites

Sure. Just add what's in red:

var amount = Field(YOUR FIELD")[color="red"].replace("$","");[/color];
// convert cent-only values to ##¢ format
if (Left(amount,1) == ".") amount = Right(amount,2) + "¢";
// convert dollar values to $#.## format
else if (amount.indexOf("%") == -1) amount = "$" + amount;
// add superscripting for symbols
amount = amount.replace("$","<superscript>$</superscript>").replace("¢","<superscript>¢</superscript>").replace("%","<superscript>%</superscript>");
return amount;

Although you'll still have a problem if the end user is able to place a leading zero for a cents-only value (i.e. "0.49"). For this reason, when we create a portal, we usually limit the characters that can be typed in the field and then "clean up" the result before forwarding to FP.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...