Skip to main content
Participant
April 28, 2023
Question

Don't want it to Round up??

  • April 28, 2023
  • 2 replies
  • 766 views

I have a formula script that I have: 

var v1 = Number(this.getField("NMS").value); 

var v2 = Number(this.getField("CMS").value); 

var v3 = Number(this.getField("CMS").value); 

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

else event.value = (v1-v2)/v3;

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

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

 

They don't want it to round up but they also want me to leave it at two decimals. 

Can someone please help me. 

This topic has been closed for replies.

2 replies

Nesa Nurani
Community Expert
Community Expert
April 29, 2023

There is no need to use two variables for same field.

toFixed() will still round result.

You can use this:

var v1 = Number(this.getField("NMS").valueAsString); 
var v2 = Number(this.getField("CMS").valueAsString); 

function twodecimals(v, d) {
return (Math.floor(v * Math.pow(10, d)) / Math.pow(10, d)).toFixed(d);}

if (v1==0 || v2==0) event.value = ""; 
else
event.value = twodecimals((v1-v2)/v2, 2);
try67
Community Expert
Community Expert
April 28, 2023

Set the field's Format to None, and change the end of the code to this:

 

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