Format a number

Results 1 to 2 of 2

Thread: Format a number

  1. #1
    Join Date
    Dec 1969

    Default Format a number

    How could I format a number in Javascript? For example: "12.3406659" into "12.34"

  2. #2
    Dan Evans Guest

    Default RE: Format a number

    If you want 2 decimcal places you could multiply it by 100, round it off using Math.round(x) and then divide it by 100 again.<BR><BR>Or you could use this little function:<BR><BR>//Function to round num to x decimal places<BR>function xdp(num, x) {<BR> return Math.round(num * Math.pow(10, x)) / Math.pow(10, x);<BR>}<BR><BR>Hope this helps,<BR><BR>-Dan Evans

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts