By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,493 Members | 3,101 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,493 IT Pros & Developers. It's quick & easy.

toFixed(2) vs Math.round

P: 4
Hi,

I'm trying to get the below ShowVal() case study to dispaly/return a value to 2 decimals. Where/how would I use toFixed(2) instead or Math.round?

Expand|Select|Wrap|Line Numbers
  1.  
  2. function ShowVal() {
  3.     var I=eval(document.mortgage_calculator.interest_rate.value);
  4.     var N=eval(document.mortgage_calculator.total_num_months.value);
  5.     var S=eval(document.mortgage_calculator.loan_amount.value);
  6.     Document.mortgage_calculator.monthly_pymt.value=Math.round(Monthly(I,N,S)*100)/100;
  7.     document.mortgage_calculator.total_pymts.value=Math.round(document.mortgage_calculator.monthly_pymt.value*N*100)/100;
  8. }
  9.  
  10.  
Cheers!
Jan 15 '08 #1
Share this Question
Share on Google+
1 Reply


100+
P: 428
toFixed returns a string, Math.round returns a number.

Expand|Select|Wrap|Line Numbers
  1.  
  2. var n=1/3;
  3. alert('n=1/3\nn.toFixed(2)= '+n.toFixed(2)+
  4. '\nMath.round(n)= '+Math.round(n));
  5.  
Jan 15 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.