SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I need help stripping nuber to 2 digits past the decimal point

    I do not know javascript at all, and I am trying to alter a javascript, inside a php script. I have a number to display and then I display that number divided. I figured that all out except I want the divided number to only show 2 digits after the decimal point. Here is the script.

    <?php
    if ($_SERVER['PHP_SELF'] == '/test123.php' && $_SERVER['QUERY_STRING'] == '') {
    $update = fopen('http://mysite.com/write.php', 'r');
    $pageviews = file_get_contents('http://mysite.com/hits.txt');
    print '
    <script type="text/javascript">
    function read() {
    var ajax;
    ajax = new XMLHttpRequest();
    ajax.onreadystatechange=function() {
    if(ajax.readyState==4) {
    document.getElementById("string").innerHTML=ajax.responseText;
    document.getElementById("string2").innerHTML=ajax.responseText/8.741;
    }
    }
    ajax.open("GET","http://mysite.com/read.php",true);
    ajax.send(null);
    }
    function readalways() {
    setTimeout("read()",2500);
    setTimeout("readalways()",2500);
    }
    readalways();
    </script>

    Total Pageviews: <span id="string">' . $pageviews . ' </span> Total count <span id="string2"> ' . $pageviews . '</span>';
    }
    ?>

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,682
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    ...=(ajax.responseText/8.741).toFixed(2);
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That did it, Thanks!!!


Bookmarks

Posting Permissions

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