www.webdeveloper.com
Results 1 to 5 of 5

Thread: [RESOLVED] six decimals after the period

  1. #1
    Join Date
    Aug 2005
    Location
    Earth
    Posts
    198

    resolved [RESOLVED] six decimals after the period

    I have a unit converter and since the resultant number can be small or big, the requirement is to have only six decimals after the period. Like: 9680.123456

    I have used this successfully:
    v4 = parseFloat(Math.round(v2 * 100) / 100).toFixed(6);
    document.MainForm.answer.value = (v4);

    where v2 is the resulting number and v4 is displayed.

    Issue is when the resulting number doesn't have decimal numbers but only 0 it is still displayed as:
    98261.000000

    I don't want these zeroes!! Pls help

  2. #2
    Join Date
    Dec 2008
    Posts
    488
    Seems to me that what you really need to do is to round to the nearest millionth, rather than using toFixed(). This way, there will never be trailing zeros, and the number will never be more than 6 digits after the decimal:

    Code:
    v4 = Math.round(v2 * 1000000) / 1000000;
    document.MainForm.answer.value = (v4);

  3. #3
    Join Date
    Aug 2005
    Location
    Earth
    Posts
    198
    It worked!! thanks soooooo much

  4. #4
    Join Date
    Dec 2008
    Posts
    488
    No problem at all! I know sometimes when I'm working on a problem, things get overly complicated and it often helps to have a fresh perspective to simplify it again.

  5. #5
    Join Date
    Aug 2005
    Location
    Earth
    Posts
    198
    so true and at times the solution is very simple n yet we get so stressed out that can't figure it out! thank u once again

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles