Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to calculate 0/0 and give 100%

Participant ,
Oct 03, 2017 Oct 03, 2017

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

TOPICS
Acrobat SDK and JavaScript , Windows
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 04, 2017 Oct 04, 2017

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 04, 2017 Oct 04, 2017

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 04, 2017 Oct 04, 2017
LATEST

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.

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

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;

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

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.

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