## Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.

• Desperate help with Calculating Adobe Javascript

# Desperate help with Calculating Adobe Javascript

New Here ,
Aug 10, 2021 Aug 10, 2021

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.

TOPICS
How to, JavaScript

Views

35

Likes

Report

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

Adobe Community Professional , 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...

Likes

2 Replies 2
Aug 10, 2021 Aug 10, 2021

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.

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Aug 10, 2021 Aug 10, 2021

Copied

LATEST

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

Likes

Report

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