Solved

Livecycle - Display field as percentage with one decimal place

Posted on 2009-07-12
11
2,086 Views
Last Modified: 2012-06-22
How do I change the display parameters of a calculated field which displays the results as a percentage which will add one decimal place to the resulting percentage number.

All works except that the field display of percentage does not show a single decimal place.

I have changed the field from Numeric to Decimal with appropriate trailing digits, but, the field still only shows the whole number percentage.

Example: 0.548 as a field value displays 55% but I want it to show 54.8%
0
Comment
Question by:Lucrecious
  • 6
  • 5
11 Comments
 
LVL 15

Expert Comment

by:mohan_sekar
ID: 24840078
Try this - util.printf("%.2f", calculatedFieldValue);
0
 
LVL 1

Author Comment

by:Lucrecious
ID: 24840964
I already have the following javascript running in this field:

if (xfa.resolveNode("Total-Event-Sales-Target.Total-Event-Sales-Target-Sunday").rawValue != 0) {
(xfa.resolveNode("Total-Event-Sales-Actual.Total-Event-Sales-Actual-Sunday").rawValue - xfa.resolveNode("Total-Event-Sales-Target.Total-Event-Sales-Target-Sunday").rawValue) / xfa.resolveNode("Total-Event-Sales-Target.Total-Event-Sales-Target-Sunday").rawValue;
} else {
    // Set field to blank (or whatever else you would want) here

}

The display pattern is set to num.percent{}.

How do I incorporate your script above within the calculation set in this field?

0
 
LVL 15

Expert Comment

by:mohan_sekar
ID: 24841015
Store the rawValue in a variable and then format it using util.printf("%.1f", rawValue);
0
 
LVL 1

Author Comment

by:Lucrecious
ID: 24841076
Can you provide details as to how the javascript calculation can be stored as a variable?

If you can paste the completed code into a response I will use the full 750 points on my account for the solution.

0
 
LVL 15

Expert Comment

by:mohan_sekar
ID: 24842327

var fld1 = 0;
if (xfa.resolveNode("Total-Event-Sales-Target.Total-Event-Sales-Target-Sunday").rawValue != 0) {
fld1 = (xfa.resolveNode("Total-Event-Sales-Actual.Total-Event-Sales-Actual-Sunday").rawValue - xfa.resolveNode("Total-Event-Sales-Target.Total-Event-Sales-Target-Sunday").rawValue) / xfa.resolveNode("Total-Event-Sales-Target.Total-Event-Sales-Target-Sunday").rawValue;

util.printf("%.1f", fld1);

} else {
    // Set field to blank (or whatever else you would want) here

}
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:Lucrecious
ID: 24842529
Almost there.

Remember that percentage fields are formatted as follows:
.18 as a value translates to 18%
.183 as a value translates to 18.3%

therefore, I changed the:
util.printf("%.1f", fld1);

to:
util.printf("%.3f", fld1);

however, without the Display pattern set as num.percent{}

I get the value of: 0.183

when the Display Pattern for the field is set to num.percent{}

I still get the value showing as: 18%

with no decimal place.

I would like the code to show the proper field display without using the Display Pattern.

Is the code able to show the display correctly?
0
 
LVL 1

Author Comment

by:Lucrecious
ID: 24842623
Acutally, Mohan the field calculates the decimal value with the script I currently have for the correct number of decimal places. When num.percent() is turned off as a Display Pattern the calculated value is absolutely correct. What I need is that the Display Pattern is able to show the percent value with once decimal place. Therefore, is it possible to include code within the num.percent() display pattern to allow for once decimal place? Does num.percent(%.3f) or some other variant make sense?

0
 
LVL 15

Expert Comment

by:mohan_sekar
ID: 24842625
Ok, remove Display pattern and modify the printf statement like this

util.printf('%.1f%',(i*100));
0
 
LVL 15

Accepted Solution

by:
mohan_sekar earned 500 total points
ID: 24842631
0
 
LVL 1

Author Comment

by:Lucrecious
ID: 24842663
Thanks Mohan, that was an answer to my question on their forums which I failed to check.
You get the points. It works perfectly. Thank you for all your efforts.
0
 
LVL 1

Author Closing Comment

by:Lucrecious
ID: 31602609
Mohan rocks!!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

One of the questions I get asked again and again is how to validate a field value in an AcroForm with a custom validation script. Adobe provided a lot of infrastructure to do that with just a simple script. Let’s take a look at how to do that wit…
Inserting page numbers in Portable Document Files not only enhances manageability but also makes them look professional. With numbered pages, the file appears more organized and it becomes easier to search for a particular page. The size and the vol…
We often encounter PDF files that are pure images, that is, they do not have text characters, but instead contain only raster graphics. The most common causes of this are document scanning software and faxing software/services that create image-only…
In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now