Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Exit

- Home
- Acrobat
- Discussions
- Adding Rounded Numbers AEM Designer/Livecycle

- Adding Rounded Numbers AEM Designer/Livecycle

0

Adding Rounded Numbers AEM Designer/Livecycle

/t5/acrobat-discussions/adding-rounded-numbers-aem-designer-livecycle/td-p/10632135
Sep 25, 2019
Sep 25, 2019

Copy link to clipboard

Copied

Building a budget, and in the last column I'm trying to get the sum of two rounded numbers, but instead of summing up two rounded numbers, it's summing up the ACTUAL numbers. Any suggestions?

For instance, if someone is asking for 10% of $25 for two years, that rounds up to $3 per year (or $6 for two years), but the sum shows me $5. How can I add just the rounded numbers?

Hopefully this makes sense.

Community guidelines

Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

11
Replies
11

/t5/acrobat-discussions/adding-rounded-numbers-aem-designer-livecycle/m-p/10638241#M152051
Sep 28, 2019
Sep 28, 2019

Copy link to clipboard

Copied

If you don't separate your arithmetic functions with parenthesis javascript will decide on its own interpretation of the whole operation you are trying to achieve.

See here:

https://www.digitalocean.com/community/tutorials/how-to-do-math-in-javascript-with-operators

Also, to round up to the nearest integer you need to use Math.round() function in your script.

You may want to try something like :

event.value = Math.round((this.getField("yourfielnamehere").value)*(.10))*2;

This will round up the fractional part of 2.50 to the nearest integer which is 3. Then times 2 years equals which equals 6

Community guidelines

Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

lwingfield
AUTHOR

Community Beginner
,

/t5/acrobat-discussions/adding-rounded-numbers-aem-designer-livecycle/m-p/10641211#M152205
Sep 30, 2019
Sep 30, 2019

Copy link to clipboard

Copied

Thank you, I'm fairly new to scripting etc, so I'm not understanding this quite well. This is a visual of what I have

As you can see the grey columns round up to $3 , how do I get the blue column to add up the $3 plus $3 to get $6 as the total? Right now it totals both as $5 - so using the ACTUAL value instead of the rounded values. Right now in the two cells that say "Total to be paid by Grant" I have this formula:

$.rawValue=Round(Position1CY21AnnualSalaryBudget*Position1CY21PercentageSalaryPaid,0)/10

In the total to be paid for the two years I have:

this.rawValue=round(Position1CY21TotalSalarytobePaidbyGrant+Position1CY22TotalSalarytobePaidbyGrant,0)

Hopefully that makes sense.

Community guidelines

Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

/t5/acrobat-discussions/adding-rounded-numbers-aem-designer-livecycle/m-p/10641403#M152215
Sep 30, 2019
Sep 30, 2019

Copy link to clipboard

Copied

Community guidelines

/t5/acrobat-discussions/adding-rounded-numbers-aem-designer-livecycle/m-p/10641380#M152214
Sep 30, 2019
Sep 30, 2019

Copy link to clipboard

Copied

It is easier if you express what you want to do in plain English (at least that is what I am learning from some of the Thom Parker tutorials that I've been consulting with other blogs and tutorials from other admirable users in these forums)... I am also new to all this.

By phrasing your arithmetic function in plain English, it simply allows you to see the intent before we break our heads trying to figure out how to code:

What you want basically is that when a number is mutliplied by 10 percent the resulting value is rounded up and not displayed as a 2.50 decimal.

To accomplish the roundup portion of your equation you need to add additional functions to your script.

A good understanding of the arithmetic functions and arithmetic operators in javascript will help see the example I posted earlier for you more clear (is not a great line of code but it worked for me).

For example, if we write down how your arithmetic equation looks like right now it would be expressed in the following manner:

What is 10 percent of 25 dollars? (which could also be expressed in different ways, wheree $25.00 times 10%, OR 25*(10/100), OR, (25*.1) would all display the same result.

So, with that in mind the same problem is written down as such:

x = 25

y = .10

z = ? <--- what is 10 percent out of 25

And the answer would be: z = x * y ----->> 25*.1 = 2.5

We know from basic algebra rules that decimal numbers like in the case of 2.5... the number 2 (which is to the left of the period) is the round off digit as long (and IF) the number to the right of the period is greater than 5;unless you specify how to round up the resulting number from that equation, javascript, on the other hand, doesn't know this rule.

From what I'm learning javascript could (and would) interpret the equation above in different ways.

So to achieve the round off of a decimal number in javsascript we have to add a function.

Two of the functions that may allow you to work around that is the "Math.round" function and "Math.ceil". But remember, if the result would've been "2.4" when we apply Math.ceil it will round up to the largest whole number (as explained in greater detail here : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil, ) meaning that the result you get in the end would be "2".

So if we read the line that I shared earlier **event.value = Math.round((this.getField("yourfieldnamehere").value)*(.10))*2** and express it in plain english it reads like this:

what would be the 10 percent of 25 dollars in two years (and if I get a decimal value rounded it up , not down).

Sorry about this long reply but essentially what I am trying to say with all these verbage is that your best companion is always gonna be your reading time. Read, read, read... then when you are exhausted of reading, take a break, then read some more again... and again. 🙂

Community guidelines

/t5/acrobat-discussions/adding-rounded-numbers-aem-designer-livecycle/m-p/10642614#M152285
Sep 30, 2019
Sep 30, 2019

Copy link to clipboard

Copied

I apologize I made a mistake in the answer I offered in my last reply... I forgot to apply the calculation for the 10%,

The following line adds both of the CY21 and CY22 fields, applies the 10% after adding both fields and multiplies that resulting value by 2 ( to apply the two year term); and rounds the total resulting number

event.value = Math.round(((this.getField("Position1CY21TotalSalarytobePaidbyGrant").value+this.getField("Position1CY22TotalSalarytobePaidbyGrant").value)*.10)*2);

OR,

This line calculates the 10% individually for each of the CY21 and CY22 fields and adds their resulting values , then multiplies that resulting value by 2 (to apply the two year term), and rounds up the resulting number:

Math.round((((this.getField("Position1CY21TotalSalarytobePaidbyGrant").value*.10)+(this.getField("Position1CY22TotalSalarytobePaidbyGrant").value*.10)*2);

AND, don't forget to click select Properties in this paid total field, then select the FORMAT tab , then "Number", select 2 to instruct the formatting of the nuber to be displayed with two decimal spaces to the right of the period, and and then the currency symbol.

To recap in plain English this would be expressed like:

Calculate 10% for each of the salaries to be paid by grant during the fiscal years CY21 and CY22 respectively; then multiply that total by 2 years, and if the result is a decimal number round it up to the next highest integer number, not to the next highest whole number.

Community guidelines

/t5/acrobat-discussions/adding-rounded-numbers-aem-designer-livecycle/m-p/10642858#M152295
Oct 01, 2019
Oct 01, 2019

Copy link to clipboard

Copied

Community guidelines

/t5/acrobat-discussions/adding-rounded-numbers-aem-designer-livecycle/m-p/10642917#M152301
Oct 01, 2019
Oct 01, 2019

Copy link to clipboard

Copied

I see... I got more homework to do

Community guidelines

/t5/acrobat-discussions/adding-rounded-numbers-aem-designer-livecycle/m-p/10646161#M152561
Oct 02, 2019
Oct 02, 2019

Copy link to clipboard

Copied

Ok so I was thinking that if this is the formula that is working for the columns that are rounding up respectively with no problem then, instead of multiplying by two, just add these fields together

**$.rawValue=Round(Position1CY21AnnualSalaryBudget*Position1CY21PercentageSalaryPaid,0)/10**

AND,

**$.rawValue=Round(Position1CY22AnnualSalaryBudget*Position1CY22PercentageSalaryPaid,0)/10**

USING SOMETHING LIKE:

**$.rawValue=Round(((Position1CY21AnnualSalaryBudget*Position1CY21PercentageSalaryPaid,0)/10)+(Position1CY22AnnualSalaryBudget*Position1CY22PercentageSalaryPaid,0)/10))**

OR,

**(Round((Position1CY21AnnualSalaryBudget*Position1CY21PercentageSalaryPaid,0)/10))+(Round((Position1CY22AnnualSalaryBudget*Position1CY22PercentageSalaryPaid,0)/10))**

This is what I can think of when applying the use parenthesis in basic arithmetic functions.

Community guidelines

/t5/acrobat-discussions/adding-rounded-numbers-aem-designer-livecycle/m-p/10646988#M152607
Oct 02, 2019
Oct 02, 2019

Copy link to clipboard

Copied

I forgot to add that if the prior examples doesn't work to also try this line:

**$.rawValue=Round((Round(Position1CY21AnnualSalaryBudget*Position1CY21PercentageSalaryPaid,0)/10)+(Round(Position1CY22AnnualSalaryBudget*Position1CY22PercentageSalaryPaid,0)/10)**

If you still want to use the other line that was not rounding up the total in the last column:

**this.rawValue=round(Position1CY21TotalSalarytobePaidbyGrant+Position1CY22TotalSalarytobePaidbyGrant,0)**

Note that in the line above you've spelled "**round**" (all in lower case and not "**Round**" (with the first letter ("R") capitalized).

I am also eliminating the use of "**this.rawValue**" and using **$.rawValue=** which is what you identified as working in the other columns.

Another thing I noticed is that at the end of that line it ends with "**,0)**" <---- I assume this was used because you were dealing with the "2.5" totals that were adding up to 5 instead of 6.

Using the Round operator may round up a number up to the nearest trailing digit, not up to the next highest integer or whole number in the equation.. the "tofixed" fucntion will accomplish something similar. However, that still rounds up to a limit of trailing digits specified in the operation but not to the highest integer number.

To accomplish that see here : https://help.adobe.com/en_US/AEMForms/6.1/DesignerHelp/WS92d06802c76abadb-39e0256b129b8b00b71-7fa5.2... and look where it says :

"**To specify the data format for numeric fields Numeric fields can save data in Float or Integer format. The default is Float. By default, numeric data in a Decimal Field will only save a maximum of two digits after the decimal. Data beyond the second decimal place will be rounded. In the Object palette, click the Binding tab.Select the appropriate format from the Data Format list: To specify the number format as a three-part representation of a number that contains a radix character, select Float. To specify the number as any sequence of the digits 0 through 9, possibly preceded by a minus sign, select Integer.** "

Last, please check this very old thread with a correct answer in which "Ceil" operator was used instead of "Round": https://forums.adobe.com/thread/1019728

Instead of using **$.rawValue=Roun** use **$.rawValue=Ceil** like so:

**$.rawValue=Ceil(Position1CY21TotalSalarytobePaidbyGrant+Position1CY22TotalSalarytobePaidbyGrant,0)**

OR,

my way of expressing this equation would be more like this:**$.rawValue=Ceil((Round(Position1CY21AnnualSalaryBudget*Position1CY21PercentageSalaryPaid,0)/10)+(Round(Position1CY22AnnualSalaryBudget*Position1CY22PercentageSalaryPaid,0)/10)**

Please let know if this works... I really ran out of suggestions

Community guidelines

/t5/acrobat-discussions/adding-rounded-numbers-aem-designer-livecycle/m-p/13447932#M392264
Dec 27, 2022
Dec 27, 2022

Copy link to clipboard

Copied

Community guidelines

Community Expert
,

LATEST
/t5/acrobat-discussions/adding-rounded-numbers-aem-designer-livecycle/m-p/13462237#M392811
Jan 03, 2023
Jan 03, 2023

Copy link to clipboard

Copied

That is very unfortunate.

However, I cannot see how is this related to the topic about performing a JavaScript calculation with Adobe LiveCycle.

If this is an issue that you experienced in relation to how to write basic college-entry essays or personal statements, your educational institution should've taught those skills to their students already.

And while convenient, a personal statement writing service is actually an oxymoron that seems to be fueled by most education systems as we continue to move forward with technology.

For instance, You would expect from a a college preparatory school to forge competent and smart enough students so that they don't feel the need to spend money out-of-pocket and have some random stranger write something great about themselves.

That is, in addition to whatever amount of monies was taken from such students already (who were supposed to learn writing in the first place while in school).

So, who is the scammer really? the school? or the opportunist that prey on the lazy students who don't want to learn how to write their own essays?

Community guidelines

Resources

About Adobe Acrobat

Adobe Inc

Adobe Inc

Adobe Inc

Adobe Inc

Adobe Acrobat Feature & Workflow

FAQs

Copyright © 2023 Adobe. All rights reserved.