0

I have a form on a website I inherited that performs a calculation with JavaScript. I would like to know how to get the result to display 1 decimal place. I have almost no experience with JavaScript. I did a search, but didn't understand how to apply the answers. I would appreciate any help. thanks

Here is (I think) the relevant code:

function formatvalue(input, rsize) {

var invalid = "**************************";

var nines = "999999999999999999999999";

var strin = "" + input;

var fltin = parseFloat(strin);

if (strin.indexOf("e") != -1 ||

fltin > parseFloat(nines.substring(0,rsize)+".4"))

return invalid.substring(0, rsize);

if (strin.length <= rsize) return strin;

var rounded = "" + (fltin + 

(fltin - parseFloat(strin.substring(0, rsize))));

return rounded.substring(0, rsize);

}
  • 1
    I think you can easily adapt the answers on the duplicate to your case. – Felix Kling Mar 20 '15 at 21:26
  • In the case of your function, rsize seems to limit the length of the input. So if your input was 123.456, setting rsize to 5 would return 123.4 – j08691 Mar 20 '15 at 21:27
  • not sure where to set the resize value. I tried changing several of the values in the code above but it has no effect. – user3470509 Mar 23 '15 at 19:03
  • please keep in mind I did not write this code and don't know how to write javascript. I've already read similar posts in this forum and I just don't understand. I was hoping someone could tell me how to change the code I already have. – user3470509 Mar 23 '15 at 19:10

0 Answers0