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

Calculating Percentages Sample (2 digit discount % to calculate $ amount)


Level 1

Hello again, I have noticed a lot of people ask questions on how to calculate percentages easily and correctly. I recently made an invoice template that if you want to offer a discount - say 5% or 37% of the subtotal i will quickly calculate it.


Subtotal is calculated (Just a FormCalc calculation of line item totals). Discount is editable, not calculated. Both are set to display currency.


I have 3 fields (Numeric)

Subtotal,  Discount & DiscountPercent


CHANGE EVENT- DiscountPercent (2 digits, no decimal, Display Pattern is num{z9})


// This code just ensures only 2 digits can be typed in the numeric field

if (xfa.event.newText.length > 2) {
xfa.event.change = "";

EXIT EVENT - DiscountPercent

// This will populate the Discount Field on exit with the discount percentage applied to the Subtotal.

Discount.rawValue = Subtotal.rawValue * 0.01 * this.editValue 



- Adam

0 Replies

The ultimate experience is back.

Join us in Vegas to build skills, learn from the world's top brands, and be inspired.

Register Now