Feedback on: Math functions in JavaScript
Worth:
Very worth reading
Length:
Too short
Technical:
Not technical enough
Comments:
Pocket calculator do not work with IE4.0
Q:
How do you display a result in a scientific format eg 1.63E-10 and with say 2 decimals?
Rgds
Cyril
Worth:
Worth reading
Length:
Just right
Technical:
Just right
Comments:
I was interested in this article because of well known problem of precision presenting floating point numbers with JavaScript. This article focus on the problem but doesn't solve it because it is said : "Come back later to this site, to further understand the calculator that I showed you in the beginning, plus I'll show you a trick, that'll work as a nice workaround to the problem, with JavaScript being inaccurate.".
In my opinion, it will be very fine to add a solution rounding off JavaScript floating point numbers : for instance Netscape's solution which works perfectly and can be found at the following address : http://developer.netscape.com/docs/examples/javascript/rounding.html.
Best regards,
Raphael
PS : IRT is really an impressing database of knowledge. It gave me answers to my questions lots of time. Great work made by great people !
Worth:
Very worth reading
Comments:
Janus:
Great article on the oddities of using math in javascript. I've built an online-ordering system that make HEAVY usage of javascript. My problem is doing monetary calculations in script. I get the odd "negative zeros" and so on but my challenge is writing a function to round up monetary values - that is, numbers with two decimal places. I'm very close but there are still odd combinations of numbers that break the function.
Do you (I HOPE) have such a function in your "toolbox"??
Thanks,
Don Gentry
Internetwerks
Worth:
Very worth reading
Comments:
The article is very helpful. I think there is a typo in one of the functions though:
"abc() - Returns the absolute value of a number ..."
abc() == abs()
Keep up the excellent articles :)
Worth:
Very worth reading
Comments:
document.evalform.help.value
is null or is not an object
is the error message i get using
ie 5.5 to run the calculator example.
Worth:
Worth reading
Technical:
Not technical enough
Comments:
There's a mistake on the summary of the math function of javascript. The function for returning the absolute value of number is called abs() not abc().
Worth:
Worth reading
Length:
Just right
Technical:
Just right
Comments:
Due to the lack of instant knowlegde of javascript syntax I wondered what the javascript version of an absolute function would be. I found Math.abc() which is not correct... Little typo I presume. It gave me a hunch though.
Worth:
Length:
Technical:
Comments:
I just read info about using sin() cos() and even tan() i tried using these but the answers they i found to be wrong?
example:
where i = 1
Math.sin(i).toFixed(4) =0.8415 WRONG:
But if you divide i by 57.295800000006835 as in
Math.sin(i/57.295800000006835).toFixed(4) = 0.0175 Correct
(had to create for loop to find divide value which equalled the correct value (well near enough)
seems very strange? i enter 1 value and then press sin cos or tan on a calculator and it produces the correct value as stated in an trigonometry table.
Worth:
Worth reading
Length:
Just right
Technical:
Just right
Comments:
This is primarily feedback on Soner's comments. Actually, the trig functions *are* returning the correct values. They simply are not expecting degrees as input, but radians (2π radians = 360°). One rad thus equals approx. 57.2958 degrees (hence your division ratio). For most serious mathematics functions, you expect to use radians, not degrees. So it’s not an error, but you were missing the important knowledge of what was expected as input.
Worth:
Length:
Technical:
Comments:
@Soner:
3 words:
deg rad grad