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

Strange Behaviour with Form Calc

realname
Registered: Aug 15 2008
Posts: 93
Answered

Hello,
 
I have an expense form which is acting very strange. It consists of several user entered fields in one table row all formated as currency. In one of the fields however a calculation is taking place using Formcalc and the script is:
 
if(DeptCode == 722)
 
then
$=kms*.444
else
$=kms*.555
endif
 
This field is also formated to return currency. The stange part is the total which is summing up all the fields, does not round up correctly. For example, if I put in 679km which is then multiplied by .555, the total of this is $376.845, if I then put another amount in another field of i.e. $20.01, the total will return $396.85 instead of $396.86. Even stranger is if I put amounts of .01 in all of the different fields, it either does not include the .01 and skips it or will add it as .02.
 
I did try putting Ceiling in to round up but it rounded up to the highest dollar with no cents as did Round. Does anyone know how to get it to round correctly?
 

Thanks!

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
What is the precision parameter you are providing to the 'Round" and 'Ceil' functions.

Are you rounding the individual computed mileage values?

The display format does not disclose the actual value but the value rounded for the display format. You might try changing the number of decimal places to a greater precision and observe what happens. You might need to round the individual mileage computations.

George Kaiser

realname
Registered: Aug 15 2008
Posts: 93
I used the following

if(DeptCode == 722)

then
$=Ceil(kms*.444)
else
$=Ceil(kms*.555)
endif

each field is set to display as
num{($z,zzz,zz9.99)}

The km input field is set to
num{zzzzzzzzzzzz9}

I just tried increasing the fields to 3 decimal places but had the same result.


gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
You did not specify the optional 'precision' parameter value for the 'Ceil' function.

You might want to observe the results without the 'Ceil' or any other function.

I would use the 'Round' function with a precision for the decimal places of 2.

This code might illustrate the issue you are encountering:

var product = 0
var sMsg = Concat("DeptCode value: ", DeptCode)
sMsg = Concat("\u000d", "kms value: ", kms, "\u000d")
if( HasValue(DeptCode) & HasValue(kms) )then
if (DeptCode == 772)
then
product = kms * 0.444
xfa.host.messageBox(Concat(sMsg, "Computed value: ", product) )
else
product = kms * 0.555
xfa.host.messageBox(Concat(sMsg, "Computed value: ", product) )
endif
endif
product



George Kaiser

realname
Registered: Aug 15 2008
Posts: 93
I don't really know what you mean by a precision parameter or where exactly I would put it. Sorry.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Accepted Answer
Have you looked at the "Scripting Reference" included as part of LiveCycle Designer's 'Help'?

Evaluates a given numeric value or expression and returns a number rounded to a given number of decimal places.

Syntax
Round(n1 [, n2])

Parameter Description
n1 A numeric value or expression to be evaluated.
n2 (optional) The number of decimal places with which to evaluate n1 to a maximum of 12.

If you do not include a value for n2, or if n2 is invalid, the function assumes the number of decimal places is 0.

FormCalc follows the IEEE-754 international standard when handling floating point numeric values.

George Kaiser

realname
Registered: Aug 15 2008
Posts: 93
Thank you, I hadn't looked at that before now. It now seems to be working correctly.