Jump to content

subscript not flush with top of price


Recommended Posts

In FusionPro, I occasionally have to add prices and I also make a subscript for the $ sign and the trailing .00.

I can't seem to get those two subscript numbers to flush to the top of the main price no matter how much leading I apply. My customer complains that that is how they want the prices to look.

Is there any rule that can make that happen?

Thank you,

Rayed

Link to comment
Share on other sites

Based on the context of what you're trying to accomplish, I'm assuming you mean superscripting and not subscripting. There are two ways to alter the offset of the superscript:

 

1. In the text editor, click Paragraph > Global Settings and alter the superscript offset ratio until you find the positioning you like. Keep in mind that this change will be applied to all areas of your template where you're using superscripting.

 

2. You can edit rule to be something like this:

return '<p br=false superoffset=45><superscript>$</superscript>5<superscript>00</superscript>';

Where the dollar sign and the '00' both have a superscript offset of 45%

Link to comment
Share on other sites

step, curious how you could write that rule using a variable field. Say my field contained something like $123.45. Is there a way to globally superscript the dollar sign as well as any decimal value using a Right Trim of 2 on my data field?

 

Trying to figure out how to rewrite the return line since right now all it does is superscript the dollar sign. Just messing with it if I ever need it. I would just use the global setting for size and offset.

 

var s = Field("Price"); 
var c = Right(Field("Price"),2)
return s.replace(/\$/g,"<superscript>$</superscript>");

Edited by dreimer
Link to comment
Share on other sites

You could try a function this:

 

In your JavaScript Globals:

 

function YourPrice(price)

{
   var newYourPrice = "";
var trimPrice = ReplaceSubstring(ReplaceSubstring(price,'$',''),',','');
var decimalPrice = FormatNumber("0.00", trimPrice);
var SuperPrice = Right(decimalPrice, 2);
var NormalPrice = Left(decimalPrice, decimalPrice.length-2);

if (price != "")
{	
	newYourPrice = "<superscript>$</superscript>"+NormalPrice+"<superscript>"+SuperPrice+"</superscript>";
}

return newYourPrice;
}

 

Then call the function in a JavaScript rule:

 

return YourPrice(Field("YourField"));

 

Step might have a better solution though. :-)

Edited by David Miller
Link to comment
Share on other sites

I think the global function that David posted is a great solution to your question, Don. I did make a few adjustments to it, though, to illustrate yet another way to skin the cat. My edits remove the decimal before the superscripted cents since I know that's another frequently requested format. And also added a second conditional statement to handle cases where the price is lower than $1.00 (highlighted in red).

 

function YourPrice(price)

{
   var newYourPrice = "";
var trimPrice = price.replace(/[^\d\.]/g,''); // Strips out anything that's not a digit or a decimal
var decimalPrice = FormatNumber("0.00", trimPrice); // Formats to 2 decimals
   var SuperPrice = decimalPrice.split(".")[1]; // Everything to the right of the decimal
   var NormalPrice = decimalPrice.split(".")[0]; // Everything to the left of the decimal

   if (price != "")
{	
       // If the price doesn't start with zeros, format as $x.xx
       if (NormalPrice.replace(/0/g,'')){
           newYourPrice = "<superscript>$</superscript>"+NormalPrice+"<superscript>"+SuperPrice+"</superscript>";
       }
       [color="Red"]// If the price is cents only, format as: xx¢
       else {
           newYourPrice = SuperPrice + "<superscript>¢</superscript>";
       }[/color]
}

return newYourPrice;
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...