Skip to main content
Jan 22, 2019 9:42 PM UTC
Answered

Need javascript to calculate a percentage

Any help would be greatly appreciated. I need a java script to get the percentage of 2 numbers. I am including a picture below. For example, I need the number for Conventional Conforming divided by the Total to get the percentage used. Can anyone help?

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Jan 22, 2019 10:20 PM UTC

Sorry, didn't realize they were the same fields...

You can use this code as the custom calculation script of the percentage field, then:

var v1 = Number(this.getField("1cc").valueAsString);

var v2 = Number(this.getField("totalvolume").valueAsString);

if (v2==0) event.value = "";

else event.value = v1/v2;

4 replies

Jan 22, 2019 10:13 PM UTC

Translate
try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
Jan 22, 2019 10:20 PM UTC

Sorry, didn't realize they were the same fields...

You can use this code as the custom calculation script of the percentage field, then:

var v1 = Number(this.getField("1cc").valueAsString);

var v2 = Number(this.getField("totalvolume").valueAsString);

if (v2==0) event.value = "";

else event.value = v1/v2;

Translate
Jan 22, 2019 10:32 PM UTC

You are a lifesaver!! Thank you so much!

Translate
try67
Community Expert
Community Expert
Jan 22, 2019 10:12 PM UTC

What are the names of the fields involved?

Translate