1

This code suppose to print float value, but instead of that, the value printed like this "0", however the expected value supposes to be "0.0"

 $("#lvl_upStream").html(parseFloat(data.lvl_upStream) + " m");

in addition, the following code has been used but still print the same result.

$("#lvl_upStream").html(getFloat(data.lvl_upStream) + " m");

Value to be printed:

"lvl_upStream":0.0
Saif AL-Qiari
  • 469
  • 5
  • 20

1 Answers1

1

Use toFixed() to setnumber of digits appear after the decimal point

$("#lvl_upStream").html(parseFloat(data.lvl_upStream).toFixed(1) + " m");

var data = '0';
document.write(parseFloat(data).toFixed(1) + " m");
Pranav C Balan
  • 113,687
  • 23
  • 165
  • 188