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 do you calculate formatted values

Avatar

Level 5

I'm trying to calculate the total of 2 fields which have been formatted using math.floor; I want to calculate the formatted amount of these 2 fields, NOT the rawValue.  How can I do this?

 

example: 

Field 1 rawValue = 700.44                                    Field 1 formatted value = 700.4

Field 2 rawValue = .42                                          Field 2 formatted value = .4

Total rawValue  =  700.86 (rounded 700.9)          Total formatted value = 700.8 ;  this is what I need to do

 

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @ReluctantProgrammer 

 

Try this:

(Math.round(700.44*10)/10)+(Math.round(0.42*10)/10);

Thanks!  

View solution in original post

4 Replies

Avatar

Correct answer by
Community Advisor

Hi @ReluctantProgrammer 

 

Try this:

(Math.round(700.44*10)/10)+(Math.round(0.42*10)/10);

Thanks!  

This formula worked but taking it one step further, I'm trying to leave the field (headwaterExistingMain10) blank unless there is an amount in one of the fields in the formula using this..

 

if (headFtExistingMain10.rawValue==null)
this.rawValue==null
else this.rawValue = (Math.round(hweFtMain10.rawValue*10)/10)+(Math.round(headFtExistingMain10.rawValue*10)/10)

 

....When I Preview the form I get this error...

"Illegal value: cannot assign 'True' to xfa[0].form[0].form1[0]0.page1[0].table1[0].row5[0]0.headwaterExistingMain10[0].#value[0].#float[0]."

 

The kicker is once I click on the 'ok' button in the error box the formula works.  


 

Avatar

Administrator

@ReluctantProgrammer Thank you for sharing your answer with the AEM community. Keep the great work going. Looking forward to see more contribution from you in future. 



Kautuk Sahni