473,395 Members | 1,815 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,395 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 962
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.