These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Setting the $ and cents in a currency format to superscript

meward77
Registered: Feb 26 2010
Posts: 6

In the formatting for my text field, i have it set to make the number entered be in a currency format ($9.99) I can't figure out a way to set the dollar sign and the cents to be superscripted, and remove the decimal.

I have looked through the JavaScriptâ„¢ for Acrobat API Reference, and found the currency formatting javascript:
event.value = util.printf("$%.2f", event.value);

But I can't seem to get any of the superscripting examples to work.

My Product Information:
Acrobat Standard 9.2, Macintosh
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
To use the sub and super script, you need to use a field with the 'Allow Rich Text Formatting' option selected and then use the 'span' object in the custom format script to format each section of the formatted output.
// Create an array to hold the Span objects	var spans = new Array();// Each Span object is an object, so we must create one // monetary symbol super scriptspans[0] = new Object(); spans[0].text = "$";	 // add monetary symbolspans[0].superscript = true;	// make super script	 // monetary amont as plain textspans[1] = new Object(); // amount string regularspans[1].superscript = false; // turn off super scriptspans[1].text = util.printf("%.2f", event.value); // format amount	 // Now assign our array of Span objects to the field using field.richValue	event.richValue = spans;

George Kaiser

meward77
Registered: Feb 26 2010
Posts: 6
This worked to make the $ superscript, but it doesn't make the cents superscript. Is there any way to find the last 2 digits of the value and make them superscript or something like that?
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
You can use the "Math.floor()" to get the whole dollars and you can use the modulos operator, '%', to get the cents. And then you need to add another 'spans' element and adjust the formatting of the numbers.
// Create an array to hold the Span objects    var spans = new Array();// Each Span object is an object, so we must create one // monetary symbol as super script textspans[0] = new Object(); spans[0].text = "$";     // add monetary symbolspans[0].superscript = true;    // make super script     // dollars as standard textvar fDollars = Math.floor(event.value);spans[1] = new Object(); // amount string regularspans[1].superscript = false; // turn off super scriptspans[1].text = util.printf("%.0f", fDollars); // format dollars     // cents as super script textvar fCents = event.value % 1; // get remainder from division by 1fCents *= 100; // shift decimal placespans[2] = new Object(); // amount string regularspans[2].superscript = true; // turn on super scriptspans[2].text = util.printf("%002.0f", fCents); // format cents with leading zero and round to 2 digits // Now assign our array of Span objects to the field using field.richValue    event.richValue = spans;

George Kaiser

meward77
Registered: Feb 26 2010
Posts: 6
Thank you so much for all your help! It works perfectly!
whitewolf68
Registered: Jan 8 2011
Posts: 3
Greetings, I am a new member of the site here. I found my way here thankfully do to your post for the superscript coding. I do still have a dilemma though.

I've got everything complete and working 99% of the time. When I go to enter an amount in the field I see what I am typing but it reverts back to all zero's.

For instance if I type 19.99 it will display $0.00 instead of $19.99. If I select the field to edit it will show the field value of 19.99 still.

Any ideas how I can fix this? I've been fighting with it for weeks now trying to find a cure or a cause with no luck.

Any help you can provide is greatly appreciated.

Thank you,

Andrew