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

Desperate help with Calculating Adobe Javascript

New Here ,
Aug 10, 2021 Aug 10, 2021

Copy link to clipboard

Copied

Im trying to figure out how to put in a calculation to round a number. This is what i have in the cell now (HRS1*Rate1)/(FTGE1) but the result always comes out as an infinunt number like

0.09642871645882162. What do i need to add for it to round to the nearest 100th? Not sure if i explanied it well enough im just learing this.

default2rg180q7y73v_0-1628622562622.png

 

TOPICS
How to , JavaScript

Views

238

Translate

Translate

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 guidelines

correct answers 1 Correct answer

Community Expert , Aug 10, 2021 Aug 10, 2021

This is caused by the difficulty computers have with floating numbers precision.

You can solve it by using a script to perform the calculation, and then rounding the value to the nearest 2nd decimal, like this:

 

var v1 = Number(this.getField("HRS1").valueAsString);
var v2 = Number(this.getField("Rate1").valueAsString);
var v3 = Number(this.getField("FTGE1").valueAsString);

if (v3==0) event.value = "";
else event.value = ((v1*v2)/v3).toFixed(2);

 

This also solves another problem you have, in c

...

Votes

Translate

Translate
Community Expert ,
Aug 10, 2021 Aug 10, 2021

Copy link to clipboard

Copied

This is caused by the difficulty computers have with floating numbers precision.

You can solve it by using a script to perform the calculation, and then rounding the value to the nearest 2nd decimal, like this:

 

var v1 = Number(this.getField("HRS1").valueAsString);
var v2 = Number(this.getField("Rate1").valueAsString);
var v3 = Number(this.getField("FTGE1").valueAsString);

if (v3==0) event.value = "";
else event.value = ((v1*v2)/v3).toFixed(2);

 

This also solves another problem you have, in case the FTGE1 field is empty (or zero), because division by zero is not a valid operation.

Votes

Translate

Translate

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 guidelines
New Here ,
Aug 10, 2021 Aug 10, 2021

Copy link to clipboard

Copied

LATEST

Thank you soooo much that did it!! I was searching everywhere!!

Votes

Translate

Translate

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 guidelines