473,241 Members | 4,405 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,241 software developers and data experts.

javascript weird problem ( a newbie)

See following code:
<script type="text/javascript">
alert (2168954000534143302);
</script>
It shows : 2168954000534143200
It should have shown: 2168954000534143302

Is it because it is a very big number?
Jun 27 '08 #1
3 959
Subhash <su************@gmail.comwrote:
>See following code:
<script type="text/javascript">
alert (2168954000534143302);
</script>
It shows : 2168954000534143200
It should have shown: 2168954000534143302

Is it because it is a very big number?
Yes. It's stored as a floating point number, which consists of an
exponent and a number. Very similar to scientific notation, where
numbers are expressed as something times ten to some power. This being
computers which use binary arithmetic, the exponent is a power of two.

What you're running into is that the base number (the non-exponent
part) is of a finite length, and therefore you can cram only so many
digits of precision into it. Your number is longer than that, so the
machine stores what it can and you get an approximation of the
original.

There's a discussion of floating point number in Wikipedia:
http://en.wikipedia.org/wiki/Floating_point

--
Tim Slattery
Sl********@bls.gov
http://members.cox.net/slatteryt
Jun 27 '08 #2
On Thu, 22 May 2008 05:07:44 -0700, Subhash wrote:
See following code:

<script type="text/javascript">
alert (2168954000534143302);
</script>
It shows : 2168954000534143200
It should have shown: 2168954000534143302

Is it because it is a very big number?
Yes.

Try this:
<script type="text/javascript">
alert ("2168954000534143302"); // note quotes
</script>
Have Fun!
Rich

Jun 27 '08 #3
In comp.lang.javascript message <7e003707-02c6-4309-8462-2ab9e2e8822c@q2
7g2000prf.googlegroups.com>, Thu, 22 May 2008 05:07:44, Subhash
<su************@gmail.composted:
>See following code:

<script type="text/javascript">
alert (2168954000534143302);
</script>

It shows : 2168954000534143200
It should have shown: 2168954000534143302

Is it because it is a very big number?
The actual value stored for that number, in an IEEE Double, is
+2168954000534143232.0 but the default conversion to string zeroes
meaningless digits.
<URL:http://www.merlyn.demon.co.uk/js-misc0.htm#DW4etc.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE7 FF2 Op9 Sf3
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Vernon Peppers | last post by:
I know that there are already a bunch of these requests in the newsgroup, but no one has answered one that would help me. I have a site that uses Javascript, http://www.namemaker.com, and one of...
3
by: Peter Williams | last post by:
Hi All, I want to write some javascript for a html page which does the following. Imagine that the page contains a table with 2 columns and 3 rows, e.g.: +---+---+ | A | B | +---+---+
3
by: Newbie | last post by:
i need to use javascript in the following 2 situations but dont know how and thanks in advance: 1. i have 2 textboxes and they usually contain the same information. when the user starts entering...
6
by: gh0st54 | last post by:
Hi I have a weird javascript error that only happens on my live server when i open the page http://www.imrated.co.uk/reg.aspx i get the error 'Problems with this page ... blablabla Line : 3...
7
by: JJ | last post by:
Dear all, I have this weird problem on the website I maintain.... A few visitors seemed to be unable to XS the website. It has a front image, with a link underneeth it saying: click here to...
9
by: optimistx | last post by:
Which url in your opinion would be a good or even the best example of javascript usage in a set of pages at least say 10 or more pages? How to use css, how to split js-code to files, how to code...
2
by: | last post by:
I need to download an rss feed on a regular basis that is embedded only in javascript (external website) and store it on my webserver's hard drive someplace. The code goes like this: <script...
13
by: paragpdoke | last post by:
Hello Everyone. Merry Christmas to all ! I'm a JavaScript newbie (and new to thescripts.com too). And I have problems in working with objects in JavaScript. The problem: <a...
16
by: Raxit | last post by:
Hi, i was reading/learning some hello world program in python. I think its very simillar to Java/C++/C#. What's different (except syntax) ? what can i do easily with python which is not easy...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...

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.