Results 1 to 2 of 2

Thread: JAVASCRIPT - Rounding

  1. #1
    Join Date
    Dec 1969

    Default JAVASCRIPT - Rounding

    I am using the round function in JAVASCRIPT as follows to round to two decimal places:<BR><BR>function round(num) {<BR> return Math.round(num * 100) /100;<BR>}<BR><BR>This works fine apart from if the result is for example 10.20 my value displays as 10.2<BR><BR>Any ideas?<BR>MC

  2. #2
    Join Date
    Dec 1969

    Default You need to fix it too...

    Convert it to a string, and find how many characters are after the ".".<BR><BR>If there are none, you need to add ".00" to the end. If there is one, you need to add "0" to the end.<BR><BR>Craig.

Posting Permissions

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