473,395 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

toFixed(2) vs Math.round

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
1 4141
mrhoo
428 256MB
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

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

Similar topics

12
by: BC | last post by:
I have read the FAQ and the discussions but I am not a Javascript programmer and do not know how to make toFixed (and other techniques) work, after several attempts. The following calculations...
2
by: Nicolas | last post by:
Why does for the same code I got different result the VB code gave me what I want why not the csharp? Thank you for your help... CSHARP CODE int sx, sy; double sdegrees; sdegrees = (90 -...
6
by: ng_mr | last post by:
No, not a question about "banker's rounding" or whatever it's called. I want to round a double to the nearest 100th, so I perform the following: // original is a double double result =...
6
by: Mitchell Vincent | last post by:
Just making sure I'm not missing the boat here, but are there any special routines for doing currency math (fixed precision stuff) in .NET? The wonderful problems of doing math on decimals tend...
5
by: glegipon | last post by:
As Tom Cahill would require, my challenge is (according to the "three R's") Reproducible: if run on OS 9.x, the monthly payment does not show up in the text box: Recognizable: I believe the...
4
by: Chris Davoli | last post by:
The folllowing will round to 526, but it should round to 527. It works correctly for all other numbers, except for this one. Does anybody know of a bug in Math.Round? Dim ldecWater As Decimal =...
10
by: David Coleman | last post by:
I am running VS 2003 and have applied SP1. (On WinXP SP2, .Net 1.1) In the Command Window I get the following ? Math.Round(0.715, 2) 0.72 ? Math.Round(0.725, 2) 0.72 ? Math.Round(0.735, 2)...
6
by: Zeng | last post by:
Math.Round has good behavior as following: Math.Round(3.45, 1); //Returns 3.4. The last '5' is thrown away because 4 is even Math.Round(3.75, 1); //Returns 3.8. The last '5' is used because '7'...
4
by: =?Utf-8?B?UmVuZQ==?= | last post by:
Hello everyone I have a problem with Math.Round, it´s ocurring some strange: Math.Round(12.985) = 12.98, it´s wrong. It should be: 12.99 Why?? What is the problem? Help ME !!!!
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.