Solved

Livecycle - Display field as percentage with one decimal place

Posted on 2009-07-12
11
2,068 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
font missing in acrobat 3 63
Barcode detail gets lost in PDF 3 84
Can JavaScript be used in a PDF? 5 66
Merging PDFs with VB.NET 10 31
This article is in response to a question here (http://www.experts-exchange.com/Other/URLs/Q_28283850.html) at Experts Exchange. The Original Poster has a scanned signature and wants to make the background transparent so that the signature may be pl…
The Adobe PDF proprietary file format is recognized as secure and formulated. But these PDF files are also prone to corruption and any external threat like virus attacks, improper storage can hit PDF file integrity.This type of damages can make cruc…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

707 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

13 Experts available now in Live!

Get 1:1 Help Now