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

Learn More

View all

Sign in to view all badges

Rounding inconsistency in repeating table

Avatar

Avatar
Validate 1
Level 1
FedWorker
Level 1

Likes

0 likes

Total Posts

5 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile

Avatar
Validate 1
Level 1
FedWorker
Level 1

Likes

0 likes

Total Posts

5 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile
FedWorker
Level 1

13-03-2018

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

Accepted Solutions (0)

Answers (5)

Answers (5)

Avatar

Avatar
Boost 50
MVP
_Bruce_Robertson
MVP

Likes

269 likes

Total Posts

1,782 posts

Correct Reply

372 solutions
Top badges earned
Boost 50
Boost 5
Boost 3
Boost 250
Boost 25
View profile

Avatar
Boost 50
MVP
_Bruce_Robertson
MVP

Likes

269 likes

Total Posts

1,782 posts

Correct Reply

372 solutions
Top badges earned
Boost 50
Boost 5
Boost 3
Boost 250
Boost 25
View profile
_Bruce_Robertson
MVP

13-03-2018

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

Avatar
Boost 50
MVP
_Bruce_Robertson
MVP

Likes

269 likes

Total Posts

1,782 posts

Correct Reply

372 solutions
Top badges earned
Boost 50
Boost 5
Boost 3
Boost 250
Boost 25
View profile

Avatar
Boost 50
MVP
_Bruce_Robertson
MVP

Likes

269 likes

Total Posts

1,782 posts

Correct Reply

372 solutions
Top badges earned
Boost 50
Boost 5
Boost 3
Boost 250
Boost 25
View profile
_Bruce_Robertson
MVP

22-03-2018

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.

Avatar

Avatar
Validate 1
Level 4
MinusZero
Level 4

Likes

30 likes

Total Posts

326 posts

Correct Reply

54 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile

Avatar
Validate 1
Level 4
MinusZero
Level 4

Likes

30 likes

Total Posts

326 posts

Correct Reply

54 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile
MinusZero
Level 4

14-03-2018

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

Avatar
Validate 1
Level 1
FedWorker
Level 1

Likes

0 likes

Total Posts

5 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile

Avatar
Validate 1
Level 1
FedWorker
Level 1

Likes

0 likes

Total Posts

5 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile
FedWorker
Level 1

14-03-2018

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

Avatar
Validate 1
Level 4
MinusZero
Level 4

Likes

30 likes

Total Posts

326 posts

Correct Reply

54 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile

Avatar
Validate 1
Level 4
MinusZero
Level 4

Likes

30 likes

Total Posts

326 posts

Correct Reply

54 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile
MinusZero
Level 4

13-03-2018

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.