Copy link to clipboard
Copied
Friends,
Good afternoon.
I have 04 Text Box where I preform to perform some mathematical operations.
For example:
The first calculation is done in Box 3, where I subtract box1-box2 - This is ok.
Already the Box4, I do the percentage calculation of the division of Box2 / Box1. When I have values, it gives me the result in%. But when I do not have values or all are zero (0), it returns me an error. I wanted a JS code where doing a division of 0/0 would return me 100%. can you help me?
Oh, I'd like to know if you can do some value counting in a textbox. For example, I have 10 textboxes that should be filled with text. in another textbox, can you create a JS to assign the value of 1 to each filled txtbox and calculate the total amount?
Abs,
Berg
Copy link to clipboard
Copied
0/0 is an error. It has no valid answer and you cannot change that. So just check your values FIRST and get the answer you want instead of dividing. Generally you should do this before any division calculation. Zero on top is fine, zero on the bottom is wrong.
Copy link to clipboard
Copied
I totally agree, but I use this in excel, and I use the = SE condition, where I say that if the division value is 0/0, it returns me 100%. This calculation is related to security actions encountered and security actions implemented. That would give me a percentage of implemented actions. But if I did not find any action to do, it means that everything is correct and therefore the performance of the performance is 100%. So I need the division by zero directs me to 100%. It would be as if I were ordering a condition, you see.
Copy link to clipboard
Copied
Actually I tried this in Excel if I divide one cell by another and they are both zero, the result shows "#DIV/0!". Even if I change the format to percentage.
Copy link to clipboard
Copied
You can do it like this:
var v1 = Number(this.getField("Box2").value);
var v2 = Number(this.getField("Box1").value);
if (v2==0) event.value = 1;
else event.value = v1/v2;
Copy link to clipboard
Copied
We have to work with the tools we have, each different. Excel might do this. JavaScript does not. Therefore you MUST use a condition, as shown.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now