Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org

Feedback: Math functions in JavaScript

Feedback on: Math functions in JavaScript

Sent by Cyril on February 15, 2000 at 07:43:20: - feedback #818

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


Sent by Raphael Augustin on August 26, 2000 at 20:06:19: - feedback #1679

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 !


Sent by Don Gentry on November 07, 2000 at 22:51:52: - feedback #1972

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


Sent by Lisa on November 24, 2000 at 17:40:53: - feedback #2058

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 :)


Sent by billemery on March 27, 2001 at 12:00:26: - feedback #2544

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.



Sent by anonymous on June 12, 2002 at 07:44:06: - feedback #3944

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().


Sent by Patrick Pietersz on June 18, 2002 at 06:15:25: - feedback #3952

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.


Sent by Soner on Saturday May 26, 2007 at 05:08:49 - feedback #4632

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.





Sent by Fenevad on Thursday April 17, 2008 at 07:03:04 - feedback #5249

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.




Sent by noname on Monday October 27, 2008 at 08:42:05 - feedback #5326

Worth:

Length:

Technical:

Comments:
@Soner:

3 words:

deg rad grad




©2018 Martin Webb