Re: Round off
- From: Dr John Stockton <jrs@xxxxxxxxxxxxxxxxxx>
- Date: Fri, 7 Apr 2006 22:12:58 +0100
JRS: In article <2xkZf.319$Mf.218@xxxxxxxxxxxxxxxxxxxxxx>, dated Thu, 6
Apr 2006 22:59:22 remote, seen in news:comp.lang.javascript, Hal Rosser
<hmrosser@xxxxxxxxxxxxx> posted :
"Dr John Stockton" <jrs@xxxxxxxxxxxxxxxxxx> wrote in message
news:CSrcoUMz3YNEFwiH@xxxxxxxxxxxxxxxxxxxxx
JRS: In article <_2_Yf.82$Mf.27@xxxxxxxxxxxxxxxxxxxxxx>, dated Wed, 5******
Perhaps you could ask your mathematics teachers about the conceptual
difference between rounding to a multiple of 0.01 giving a Number, and
rounding to two decimal places which necessarily gives a String.
The OP asked about rounding a number to 2 decimals - not about converting it
to a string.
***
"Two decimal places" implies a string. Number 3.5 is a multiple of
0.01, but it has only one decimal place. String "3.50" represents a
multiple of 0.01, and has two decimal places. They have the same
numerical value.
===========
In my system, somewhat to my surprise, Math.pow(10, N) is faster than
Number("1e"+N), and is sufficiently accurate[*] ; unless I hear that the
contrary is generally true, I'll change my pages.
[*] for (j=0; j<40; j++) document.writeln(j, " ", +("1E"+j), " ",
t=Math.pow(10, j), " ", t%1, "<br>")
My results for 23 & 29 need some more thought.
FAQ 4.6 can be correspondingly changed.
I'm sure that code is very clever and correct.
It is, however just so mush gibberish to someone who's trying to learn
something.
Don't quote what you're not commenting on. It confuses and annoys your
readers.
The FAQ author evidently did not feel that the comment presented in and
for StrU and its friends in js-round.htm needed to be repeated in the
FAQ, given that he was providing a link to js-round.htm. There, StrU
currently starts
function StrU(X, M, N) { // X>=0.0 ; gives M digits point N digits
Remember that the FAQ is posted twice a week, and that some users will
be on dial-up or wireless links. That is why (IMHO) the FAQ rightly
gives brief answers with links to further information.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME ©
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
.
- Follow-Ups:
- Re: Round off
- From: joe . eas
- Re: Round off
- References:
- Round off
- From: Phat G5 (G3)
- Re: Round off
- From: Hal Rosser
- Re: Round off
- From: Dr John Stockton
- Re: Round off
- From: Hal Rosser
- Round off
- Prev by Date: Re: Decimall Float Question
- Next by Date: pass option value as variable for javascript function
- Previous by thread: Re: Round off
- Next by thread: Re: Round off
- Index(es):
Relevant Pages
|