have a problem with javascript caculate

W

w2ajax

Hi all,
my script:
<script>
var t= 2.2 - 1.5; // t = 0.7
alert(t);
</script>
but result's alert: 0.7000000000000000002
Help me!
 
D

dhtmlkitchen


But now I'm reading about JScript's toFixed bug.

toFixed

The javascript internal method Number.toFixed() is only available in
later browsers, and even then will not always be suitable. The
internal method may err : try 0.07 and 1.129 for possible truncation;
try toFixed(0) for 0.50 to 0.94 or to 0.999...

" ... bug in Number.toFixed(), namely that for values n in
{(-0.94,-0.5], [0.5,0.94)}, n.toFixed(0) returns 0 instead of -1 or
1."

Apparently, (0.07).toFixed(1) gives 0.0.

http://www.merlyn.demon.co.uk/js-rndg1.htm

I'm always continually amazed at what A piece of junk IE is.

Garrett
 
S

Steve Swift

And I am always continually amazed at peoples attitude about IE, quick
to point out what "junk" it is but fail to mention what "junk FF is"
when a bug in FF is pointed out.

Bill Gates became the world's richest man, probably more by selling
Internet Explorer than anything else. One expects a quid pro quo.
With Firefox you get value for money.
 
D

dhtmlkitchen

Steve Swift said the following on 8/15/2007 2:51 AM:



I don't see how you can even come close to making that claim when Bill
Gates was the world's richest man long before Internet Explorer became
dominant. What made Gates the richest man was cornering the OS market.


And what you get for IE is what you deserve for it.


What I get with Firefox are bugs just like IE has, but, I get a larger
memory usage and a slower loading browser to browse with. That is,
unless I want to pre-load it and have it loaded and wasting my RAM just
so it loads a little faster.

I am not defending IE, it has its problems just as Firefox has bugs.
What I find ironic, and always will, are the people that want to bitch
about IE but when a bug is pointed out in FF the defense is "But IE
sucks". Sheesh. At least admit it isn't perfect and move on.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/

IE 4 was a big milestone. Improvements since then have not kept up
with Mozilla.

It seems that MS shot themselves in the foot with DHTML. Now they have
to compete with this free technology by creating Vista for fat
clients.

Firefox does not exhibit the same behavior with toFixed. In general,
FF bugs are fixed pretty quickly, and I'd bet that there have been
more bug fixes in FF over the years than IE. IE just kind of drags its
feet.
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]>,
It is also covered in the group FAQ although it is not in an entry
dedicated to toFixed (It is in 4.6).

It is a little hard to spot, though, because in that section code-in-
text is not marked with <CODE>.

The code in the code-box of that section is somewhat different from what
I would presently recommend.

Re FAQ section 4.30 : if anyone here is able to influence, directly or
indirectly, ECMA 4 or ISO/IEC 3 --- observing that implementations of
document.lastModified are commonly flawed, I suggest the addition of
document.LastModHeader, defined as a string which exactly matches the
Last-Modified header line (from which lastModified is derived), and is
an empty string if the header is missing. Implementation is clearly
trivial. No attention to be paid to whether the "body" of the header
line is RFC-compliant (though I expect it always is).
 
D

Dr J R Stockton

In comp.lang.javascript message said:
Dr J R Stockton said the following on 8/16/2007 12:48 PM:

I believe that I have asked in the past when you make such statements
about code not being what you would recommend what you would recommend
and you never give a straight answer.

What code would you recommend to replace whatever code is in 4.6?

The code which the obvious link in that section of the FAQ leads to, of
course. That will always give my currently-recommended code (as long as
the site survives). That includes preselected code tests, a test form
in which one can choose whatever arguments one wishes for each of the
functions I have in the code, and one in which a user-supplied function
can be correspondingly tested.
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]>,
I have no intentions of checking your site daily/weekly to see if you
have updated code that you would like to see in the FAQ.

But when I tell you that the code in a section of the FAQ is out-of-
date, and that section of the FAQ cites a page in my site, you should
not find it too difficult to deduce when and where to look.
I can see why Richard ignored most of your requests for changes. You
don't offer any changes, you simply say "That should be changed".

When there is an answer that the FAQ fails to give, and it is an answer
that I would like to know, I can hardly be expected to provide it.

Don't try and excuse yourself by reference to another failed FAQ
maintainer; the recent list of changes is derisory.
 
D

Dr J R Stockton

In comp.lang.javascript message said:
What is derisory is your attitude, expectations and the FAQ in general.
I have, on at least 3 occasions, given you a remedy for your
unhappiness with the current situation.

No; you have made a useless suggestion.

You hastily volunteered to be FAQ maintainer; you have achieved, since
March, almost nothing in that direction.

However, you have meanwhile indulged in a great deal of long-winded
posting in this newsgroup and at least one other. Some of that,
certainly, was useful; but most of that part could and would have been
provided by others of equal or greater expertise. If you had spent that
time on fulfilling your promise to maintain the FAQ, then many of the
suggested valuable changes could by now have been incorporated in a
published FAQ.

So : my present attitude towards you is both caused and justified by
your disgraceful failure; I had, if not expected, at least hoped that
you would do what you undertook to do; and, as you say above, the FAQ is
- as far as progress is concerned - indeed worthy of derision.

You should follow Nixon's example.

----

If there is any real likelihood of your updating FAQ 4.6 as suggested in
the near future, you'd better collect the code a.s.a.p; it is very
likely that, in order to avoid the new usage guillotine, I will have to
disable much more of the javascript part of my Web site.
 
D

Dr J R Stockton

In comp.lang.javascript message said:
What is derisable about that document is the entire document itself and
the premise that it does what was intended of it and it doesn't. It is
very dated and about half of it is irrelevant to the current state of
JS on the web.


You have been FAQ maintainer for something like nine months. Its
present state is therefore your responsibility.

Rather than making pointless long-winded posts intended as self-
exculpation, you should use the time to get on with the job.

It's still not too late to prove that what WSC (allegedly) said about
Americans was correct.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,158
Messages
2,570,882
Members
47,414
Latest member
djangoframe

Latest Threads

Top