Go Back   CodingForums.com > :: Client side development > JavaScript programming > Post a JavaScript

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-22-2002, 02:22 PM   PM User | #1
jalarie
Regular Coder

 
Join Date: Jun 2002
Location: Flint, Michigan, USA
Posts: 593
Thanks: 1
Thanked 19 Times in 19 Posts
jalarie is an unknown quantity at this point
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;
}
jalarie is offline   Reply With Quote
Old 07-22-2002, 06:04 PM   PM User | #2
jkd
Senior Coder

 
jkd's Avatar
 
Join Date: May 2002
Location: metro DC
Posts: 3,163
Thanks: 1
Thanked 18 Times in 18 Posts
jkd will become famous soon enough
5.2344573.toFixed(2) == "5.23"

toFixed was introduced in IE5.5 and NS6.
__________________
jasonkarldavis.com
jkd is offline   Reply With Quote
Old 07-23-2002, 05:56 PM   PM User | #3
jalarie
Regular Coder

 
Join Date: Jun 2002
Location: Flint, Michigan, USA
Posts: 593
Thanks: 1
Thanked 19 Times in 19 Posts
jalarie is an unknown quantity at this point
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.
jalarie is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:06 AM.


Advertisement
Log in to turn off these ads.