Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Flint, Michigan, USA
    Posts
    620
    Thanks
    1
    Thanked 20 Times in 20 Posts

    Round Off

    To round off a value to a specified number of digits:

    function RoundIt(Value,Digits) {
     var P=Math.pow(10,Digits);
     var R=Math.round(Value*P)/P;
     var G=true;
     while(G) {
      R=String(R);
      var L=R.length;
      var I=R.indexOf('.');
      if (I == -1) {
       R=R+'.';
      } else {
       var D=L-I-1;
    &nbsp;&nbsp;&nbsp;if (D < Digits) {
    &nbsp;&nbsp;&nbsp;&nbsp;R=R+'0';
    &nbsp;&nbsp;&nbsp;} else {
    &nbsp;&nbsp;&nbsp;&nbsp;G=false;
    &nbsp;&nbsp;&nbsp;}
    &nbsp;&nbsp;}
    &nbsp;}
    &nbsp;return R;
    }

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    5.2344573.toFixed(2) == "5.23"

    toFixed was introduced in IE5.5 and NS6.

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Flint, Michigan, USA
    Posts
    620
    Thanks
    1
    Thanked 20 Times in 20 Posts
    That's very nice for the IE5.5 and NS6 people, but there are still quite a few who haven't gotten that far, many who are using other browsers by choice, and some visually-impaired who are forced to use other browsers out of necessity.


  •  

    Posting Permissions

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