• Global community
• Language:
• Deutsch
• English
• Español
• Français
• Português
• 日本語コミュニティ
Dedicated community for Japanese speakers
• 한국 커뮤니티
Dedicated community for Korean speakers
Exit Search
• Adding Rounded Numbers AEM Designer/Livecycle

# Adding Rounded Numbers AEM Designer/Livecycle

Community Beginner ,
Sep 25, 2019 Sep 25, 2019

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.

Views

789

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
12 Replies 12
Community Expert ,
Sep 28, 2019 Sep 28, 2019

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

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
Sep 30, 2019 Sep 30, 2019

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.

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Expert ,
Sep 30, 2019 Sep 30, 2019

Copied

In the total to be paid field this is how I would do it (and there are many different ways... but for my current NOOB level this how I would do it as a custom calcution script: event.value = Math.round((this.getField("Position1CY21TotalSalarytobePaidbyGrant").value+this.getField("Position1CY22TotalSalarytobePaidbyGrant").value)*2); And check if it works.

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Expert ,
Sep 30, 2019 Sep 30, 2019

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.

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).

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Expert ,
Sep 30, 2019 Sep 30, 2019

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.

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
LEGEND ,
Oct 01, 2019 Oct 01, 2019

Copied

Take care, AEM Designer (previously LiveCycle Designer) has a different JavaScript language. In particular, and the most obvious difference, you must not use getField in Designer scripts.

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Expert ,
Oct 01, 2019 Oct 01, 2019

Copied

I see... I got more homework to do

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Expert ,
Oct 02, 2019 Oct 02, 2019

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.

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Expert ,
Oct 02, 2019 Oct 02, 2019

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. "

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

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Dec 27, 2022 Dec 27, 2022

Copied

During their studies, students often encounter scammers. Especially when it comes to help with homework. I also encountered this problem. While I was looking for personal statement writing service I ran into scammers who offered help for the minimum price. And did not perform my task.

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Expert ,
Jan 03, 2023 Jan 03, 2023

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?

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Jan 06, 2023 Jan 06, 2023

Copied

LATEST

Lwingfield, I'd be happy to help you, but I don't understand these calculations at all. Yeah, I'm not really good with numbers. I hope you were able to resolve this issue. I also have a hard time doing writing assignments at university. That's why I turn to https://www.bestessay.com/buy-essay/ I chose this company because they have a scratch writing process. I started getting good grades only because of the unique content that expresses their personal point of view. Having ordered paper from them more than once, I concluded that I was dealing with professional writers.