Solved

Livecycle - Display field as percentage with one decimal place

Posted on 2009-07-12
11
2,167 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

 
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
 
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Acrobat’s JavaScript is a great tool to extend the application, or to automate recurring tasks. There are several ways a JavaScript can be added to the application or a document (e.g. folder level scripts, validation scripts, event handling scripts,…
Power PDF (http://www.nuance.com/for-business/document-imaging-and-scanning/power-pdf-converter/index.htm) is the newest product from the Document Imaging division of Nuance Communications (http://www.nuance.com/). It is available in two editions — …
In this third video of the Xpdf series, we discuss and demonstrate the PDFtoText utility, which converts PDF files into plain text files. Download and install the software.: You may have already downloaded and installed the Xpdf tools while watching…
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…

719 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