making a Javascript only use 2 numbers after the d

Results 1 to 3 of 3

Thread: making a Javascript only use 2 numbers after the d

  1. #1
    Join Date
    Dec 1969
    Posts
    70

    Default making a Javascript only use 2 numbers after the d

    Hello again...<BR><BR>I am trying to make my javascript limit the number to only 2 decimals. I just can&#039;t seem to make it work. Can anyone help me with this please?<BR><BR>Thanks,<BR><BR>Brian

  2. #2
    Join Date
    Dec 1969
    Posts
    96,118

    Default www.irt.org and the JS FAQ

    They probably have a variety of different scripts to do this.<BR><BR>My own way:<BR><BR>&#060;SCRIPT&#062;<BR>function dollars( num )<BR>{<BR> num = parseFloat( num ); // just to make sure<BR> var sign = "";<BR> if ( num &#060; 0 )<BR> {<BR> sign = "-";<BR> num = -num;<BR> }<BR> num = Math.round( 100.0 * num )<BR> if ( num &#060; 10 ) return sign + "0.0" + num;<BR> if ( num &#060; 100 ) return sign + "0." + num;<BR> num = sign + num; // convert it to a string<BR> return num.substring(0,num.length-2) + "." + num.substring(num.length-2);<BR>}<BR>

  3. #3
    Join Date
    Dec 1969
    Posts
    70

    Default Thanks Bill...

    I forgot about that site...Sorry!

Posting Permissions

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