Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list

Rounding inconsistency in repeating table

Avatar

Level 1

In our LiveCycle Designer form design we have a repeating table with a Total field. The total is rounding some numbers up and not rounding other numbers. For example:

58.81 x 42.5 = 2499.43 which is correct.

60.49 x 5.5 = 332.69 which is incorrect - it should be 332.70.


The JavaScript formula we are using is:

this.rawValue = OTRate.rawValue * Hours.rawValue

Any ideas on what is going on here???

5 Replies

Avatar

Level 7

Hi,

There is a rounding function in Livecycle, but only for FormCalc.

However, even it does some strange things. Your calculation comes to 332.695 but rounding to 2 digits gives the answer 332.69, not 332.70

Apparently Adobe dont understand how to Round.

Round

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

Syntax

Round(n1 [, n2])  

Parameters

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.

Note: FormCalc follows the IEEE-754 international standard when handling floating point numeric values. For more information, see Number literals.

Examples

The following expressions are examples of using the Round function:

Expression

Returns

Round(12.389764537, 4) 12.3898
Round(20/3, 2) 6.67
Round(8.9897, "abc") 9
Round(FV(400, 0.10/12, 30*12), 2)

904195.17. This takes the value evaluated using the FV function and rounds it to two decimal places.

See also FV.

Round(Total_Price, 2)

Rounds off the value of Total_Price to two decimal places.

Avatar

Level 10

You can use (60.49 * 5.5).toFixed(2) to get 332.70.

This is how JavaScript maths works, the same thing happens in a internet browser.

Avatar

Level 1

I'm confused. If using the field names I have above (not static numbers as in your example), would this be:

(OT.rawValue * Hours.rawValue).toFixed(2)

??


Because that doesn't work under the calculate function of LiveCycle Designer.

Avatar

Level 7

I put this in the calculate field and it calculated but still gave the wrong answer

(OT.rawValue * Hours.rawValue).toFixed(2);

1442359_pastedImage_0.png

Avatar

Level 10

I've never noticed this before, sorry for the bum steer.  I did test this in IE 11, as I always thought javascript maths worked the same, but seems IE 11 is the only one that returns 332.70, Edge, Chrome and FF return 332.69.

Maybe try

(OT.rawValue * Hours.rawValue + 0.001).toFixed(2)

I guess it has something to do with the rounding of a decimal ending in 5.