473,594 Members | 2,862 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Eval Function

Can any one help in this please.
I'm using eval function in JavaScript, But when the eval method return
a big big number the result will be a number with "E"
for example :
Eval(1000000000 000000000000) will result 1e+21
I need to get the number as it is . can i ??

Thanks in advance

Aug 10 '05 #1
4 3497
Generally no.

Javascript numbers have limited precision (i.e. they can only contain a
finite number of digits), following the IEEE standards. See:-

http://en.wikipedia.org/wiki/IEEE_fl...point_standard

You will need to research arbitrary precision mathematics if you really
need greater precision.

Aug 10 '05 #2
"tozeina" <to*****@gmail. com> writes:
I'm using eval function in JavaScript,
Probably a bad idea.
<URL:http://jibbering.com/faq/#FAQ4_40>
But when the eval method return
a big big number the result will be a number with "E"
for example :
Eval(1000000000 000000000000) will result 1e+21
That would be the default string representation of that number for
your browser. The notation "1e+21" means 1 * 10^21, i.e., 1 with
21 zeroes after it, which is exactly the number you entered.

You should also be aware, that numbers that big can't all be represented
exactly. E.g., (1e+21 == (1e+21 + 1)) gives true, because the 64 bit
floating point numbers used by Javascript does not have the resolution
to represent (1e+21 + 1).
I need to get the number as it is . can i ??


You can compute your own string representation of the number.
Maybe something like:
---
function numberToString( number, base) {
base = base || 10;
var res = [];
while (number > 0) {
var digit = number % base;
res.push((digit < 10) ? digit : String.fromChar Code(digit - 10 + 97));
number = (number - digit) / base;
}
return res.reverse().j oin("");
}
---
Call it as:
numberToString( 1e+21, 10)
Make sure base is an integer between 2 and 36!

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Aug 10 '05 #3


The number should come out as is by default, it should't use the Euler's
format, I think the issue is in your using eval(), eval() is outputting
such, instead, skip eval() altogether.
Danny
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Aug 10 '05 #4
JRS: In article <11************ *********@f14g2 000cwb.googlegr oups.com>,
dated Wed, 10 Aug 2005 05:45:37, seen in news:comp.lang. javascript,
tozeina <to*****@gmail. com> posted :
Can any one help in this please.
I'm using eval function in JavaScript, But when the eval method return
a big big number the result will be a number with "E"
for example :
Eval(100000000 0000000000000) will result 1e+21
I need to get the number as it is . can i ??


No doubt you should not in fact be using eval - see newsgroup FAQ 4.40.

In javascript, Numbers are stored as IEEE Doubles, a binary floating-
point format. If you want to see that, which you don't, consider
<URL:http://www.merlyn.demo n.co.uk/js-misc0.htm#IEEE> .

If you really do need to express a large number in fixed-point, you will
need to accept rounding errors (though it may be possible to mask the
obvious ones) - see BigStrOfMN in
<URL:http://www.merlyn.demo n.co.uk/js-round.htm#CAI>.

Alternatively, if you want results accurate past one part in about 1e15,
you can implement your own arithmetic using arrays of digits to
represent numbers. I've done it, for Pascal/Delphi integer work, in
<URL:http://www.merlyn.demo n.co.uk/programs/longcalc.pas>.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Aug 10 '05 #5

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

Similar topics

4
2026
by: Jean-Sébastien Bolduc | last post by:
Hello, I would like to associate a local namespace with a lambda function. To be more specific, here is exactly what I would want: def foo(): a = 1 f = lambda x : a*x return f
9
8455
by: HikksNotAtHome | last post by:
This is a very simplified example of an Intranet application. But, is there an easier (or more efficient) way of getting the decimal equivalent of a fraction? The actual function gets the select values, this one is a simplified version where its passed. function checkIt(selVal){ valueInDec1 = eval(selVal); //do some calculations here with valueInDec1 }
12
3425
by: knocte | last post by:
Hello. I have always thought that the eval() function was very flexible and useful. If I use it, I can define functions at runtime!! However, I have found a case where eval() does not work properly. It works, for example, when invoking functions (alert('hello')), but not for defining functions. The case occurs when retrieving the javascript code with
18
3147
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My question is what happens to the dynamically created assembly when the method is done running? Does GC take care of it? Or is it stuck in RAM until the ASP.Net process is recycled? This code executes pretty frequently (maybe 4 times per transaction) and...
3
1903
by: Pauljh | last post by:
Hi All, I'm running some javascript over a server side generated web page and have multiple generated empty select statements, that I want to populate when the page is loaded. As HTML doesn't do arrays each select is individually named withe MySelecti where i is an incremental from 1. I know all my variables are correct (i, OptionsCount) and my arrays of MyValues and MyDescription's exist for multiple enteries and if I bring out an...
7
5053
by: Darko | last post by:
Hello, I have this particular problem with eval() when using Microsoft Internet Explorer, when trying to define an event handler. This is the code: function BigObject() { this.items = new Array(); this.values = new Array();
6
3621
by: vasudevram | last post by:
Hi group, Question: Do eval() and exec not accept a function definition? (like 'def foo: pass) ? I wrote a function to generate other functions using something like eval("def foo: ....") but it gave a syntax error ("Invalid syntax") with caret pointing to the 'd' of the def keyword.
2
3668
by: Florian Loitsch | last post by:
hi, What should be the output of the following code-snippet? === var x = "global"; function f() { var x = 0; eval("function x() { return false; }"); delete x; alert(x); }
6
5899
by: RandomElle | last post by:
Hi there I'm hoping someone can help me out with the use of the Eval function. I am using Access2003 under WinXP Pro. I can successfully use the Eval function and get it to call any function with or without parms. I know that any function that is passed to Eval() must be declared Public. It can be a Sub or Function, as long as it's Public. I even have it where the "function" evaluated by Eval can be in a form (class) module or in a standard...
10
494
by: Gordon | last post by:
I have a script that creates new objects based on the value of a form field. Basically, the code looks like this. eval ('new ' + objType.value + '(val1, val2, val3'); objType is a select with the different types of objects you can create as values. I really don't like using eval, and it's causing problems, like if I do something like the following:
0
7877
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8253
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8374
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8009
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6661
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5739
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2389
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1482
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1216
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.