About 50 results
Open links in new tab
  1. How do I round a number in JavaScript? - Stack Overflow

    The actual one-liner is 'Math.round (number)'. The whole type casting business is unnecessary. In JavaScript strings are automatically coerced to numbers when needed.

  2. javascript - How to round to at most 2 decimal places, if necessary ...

    I'd like to round at most two decimal places, but only if necessary. Input: 10 1.7777777 9.1 Output: 10 1.78 9.1 How can I do this in JavaScript?

  3. How to round float numbers in javascript? - Stack Overflow

    possible duplicate of round number in JavaScript to N decimal places -- please use the search before you ask a new question.

  4. JavaScript math, round to two decimal places - Stack Overflow

    I have the following JavaScript syntax: var discount = Math.round(100 - (price / listprice) * 100); This rounds up to the whole number. How can I return the result with two decimal places?

  5. How do you round to one decimal place in JavaScript?

    Can you round a number in JavaScript to one character after the decimal point (properly rounded)? I tried the *10, round, /10, but it leaves two decimals at the end of the int.

  6. How to round up a number to a precision of tenths in JavaScript?

    This works great, but the OP asked how to round up a number, so Math.ceil should be used here instead of Math.round.

  7. Javascript: formatting a rounded number to N decimals

    It returns a string, not a number. So it doesn't round a number to N decimals, it creates a string that humans can read as a number with decimals. But ony if they, by accident, use the same sign for …

  8. How can I round down a number in Javascript? - Stack Overflow

    288 How can I round down a number in JavaScript? math.round() doesn't work because it rounds it to the nearest decimal. I'm not sure if there is a better way of doing it other than breaking it apart at the …

  9. How can I round a number in JavaScript? .toFixed() returns a string?

    277 Number.prototype.toFixed is a function designed to format a number before printing it out. It's from the family of toString, toExponential and toPrecision. To round a number, you would do this:

  10. Format number to always show 2 decimal places - Stack Overflow

    May 26, 2011 · 34 For the most accurate rounding, create this function and use it to round to 2 decimal places: