0

Hi wonder if anyone can help, I'm creating a PDF form with javascript calculation but wits not rounding to 2 decimal places, any ideas?

(function () {  

// Get the field values, as numbers  
var v1 = +getField("ANNUAL_MILEAGE").value;  
var v2 = +getField("MILES_PER_GALLON").value;  

if (v1 !== 0) {  
event.value = Number(v1) / Number(v2).toFixed(0);  
} else {  
event.value = ""; 
  }  

})();  
DJP2019
  • 69
  • 2
  • 9
  • Possible duplicate of [JavaScript math, round to two decimal places](https://stackoverflow.com/questions/15762768/javascript-math-round-to-two-decimal-places) – Noam Gur Jun 07 '17 at 14:09
  • 1. Put parens around the division, 2. Check the docs for .toFixed, 3. It doesn't matter if v1 == 0, but it sure does if v2 == 0. – James Jun 07 '17 at 14:09
  • Great I sorted that, thanks very much!!! Is there a way to remove 'infinity' if field is blank? – DJP2019 Jun 07 '17 at 15:31

0 Answers0