Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

How to devide two numeric fields?

Avatar

Level 2

Hello.

I have been trying to devide two numeric fields, called A & B, and put the result in a hidden field called C. I need the value for an XML export.

My question is; How is it possible to devide A & B? I dont have a problem in multipling other fields, but when trying to devide I get at over/underflow error.

Best regards,

Mathias

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

When dividing, it is worth checking that the value of the field under the line is not null or zero first. So the calculate event of the hidden field would look something like this:

if (b.rawValue == null || b.rawValue == 0)

{

     c.rawValue = "0"; // If c is a numeric field. If it is a text field then you could put a message "division by zero"

}

else

{

     c.rawValue = a.rawValue / b.rawValue;

}

Hope that helps,

Niall

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

Hi,

When dividing, it is worth checking that the value of the field under the line is not null or zero first. So the calculate event of the hidden field would look something like this:

if (b.rawValue == null || b.rawValue == 0)

{

     c.rawValue = "0"; // If c is a numeric field. If it is a text field then you could put a message "division by zero"

}

else

{

     c.rawValue = a.rawValue / b.rawValue;

}

Hope that helps,

Niall

Avatar

Level 2

Thanks a lot - it works!

bdgs

Mathias