How to display the result of "toPrecision" without the scientific notation?

To get a float with reduced precision, you could use toPrecision() like you do, and then parse the scientific notation with parseFloat(), like so:

result = parseFloat(num.toPrecision(2));

If you do not wish to reduce precision, you could use toFixed() to get the number with a certain number of decimals.


Number((555.55).toPrecision(2))

http://jsfiddle.net/K5GRb/


I had a similar desire to preserve a certain amount of precision, not have trailing zeros, and not have scientific notation. I think the following function works:

function toDecimalPrecision(val, digits) {
  val = (+val).toPrecision(digits);
  if (val.indexOf('e') >= 0) {
    val = (+val).toString();
  } else if (val.indexOf('.') >= 0) {
    val = val.replace(/(\.|)0+$/, '');
  }
  return val;
}