Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / November 2007



Tip: Looking for answers? Try searching our database.

Number to string??

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike - 28 Nov 2007 16:35 GMT
Why is this converted to a string???
var newidNumber =((idNumber/2).toFixed())+1;

Thanks
Mike
Henry - 28 Nov 2007 16:37 GMT
> Why is this converted to a string???
> var newidNumber =((idNumber/2).toFixed())+1;

Because the - toFixed - method returns a string.
kendalk08 - 28 Nov 2007 16:45 GMT
> > Why is this converted to a string???
> > var newidNumber =((idNumber/2).toFixed())+1;
>
> Because the - toFixed - method returns a string.

when you want to use the variable as a number use eval() to return a
number
Henry - 28 Nov 2007 16:56 GMT
> > > Why is this converted to a string???
> > > var newidNumber =((idNumber/2).toFixed())+1;
[quoted text clipped - 3 lines]
> when you want to use the variable as a number use eval() to
> return a number

No thanks, I will use the unary plus operator, the Number constructor
called as a function, parseInt or parseFloat, depending on the
situation. The - eval - function would be the absolute worst method to
use, particularly as its behaviour is unpredictable whenever its
argument is a string that does not represent a number.
kendalk08 - 28 Nov 2007 16:57 GMT
> > > > Why is this converted to a string???
> > > > var newidNumber =((idNumber/2).toFixed())+1;
[quoted text clipped - 9 lines]
> use, particularly as its behaviour is unpredictable whenever its
> argument is a string that does not represent a number.

You probably know more about Javascript, but I have been coding for
about 2 years and the - eval - function has always worked for me.
Henry - 28 Nov 2007 17:06 GMT
<snip>
>>> when you want to use the variable as a number use eval() to
>>> return a number
<snip>
>> ... . The - eval - function would be the absolute worst method to
>> use, particularly as its behaviour is unpredictable whenever its
>> argument is a string that does not represent a number.
>
> You probably know more about Javascript,

You suggested using - eval - so we are well past "probably".

> but I have been coding for about 2 years

It might be an idea to stop and RTFM soonish.

> and the - eval -
> function has always worked for me.

Even the worst ways of doing things 'work', otherwise they become the
best ways of not doing them.
nolo contendere - 28 Nov 2007 18:05 GMT
> <snip>
> >>> when you want to use the variable as a number use eval() to
[quoted text clipped - 7 lines]
>
> You suggested using - eval - so we are well past "probably".

There are such things as manners--this sentence was probably
unnecessary.
Randy Webb - 29 Nov 2007 00:00 GMT
kendalk08 said the following on 11/28/2007 11:45 AM:

>>> Why is this converted to a string???
>>> var newidNumber =((idNumber/2).toFixed())+1;
>> Because the - toFixed - method returns a string.
>
> when you want to use the variable as a number use eval() to return a
> number

Who fed you that line of incompetent ignorant crap?

Signature

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

VK - 29 Nov 2007 05:33 GMT
> kendalk08 said the following on 11/28/2007 11:45 AM:
>
[quoted text clipped - 6 lines]
>
> Who fed you that line of incompetent ignorant crap?

You mean you know a script engine where eval("2") doesn't return
typeof "number"? Which one is that (non-ECMAScript compliant by
default)?

If you foresee some dangerous consequences of eval("2") in comparison
of the +"2" trick then you should spell them for the public attention
IMHO. After all eval is not a sex with underagers or drugs to get
berserk on the combination of these four letters by itself, IMHO.
Randy Webb - 29 Nov 2007 09:25 GMT
VK said the following on 11/29/2007 12:33 AM:
>> kendalk08 said the following on 11/28/2007 11:45 AM:
>>
[quoted text clipped - 7 lines]
> You mean you know a script engine where eval("2") doesn't return
> typeof "number"?

Who said I did? I didn't. Anybody that uses eval(string) to convert
string to a number is an incompetent ignorant idiot.

> Which one is that (non-ECMAScript compliant by default)?

ECMAScript, concern, mouses rear end.

> If you foresee some dangerous consequences of eval("2") in comparison
> of the +"2" trick then you should spell them for the public attention
> IMHO. After all eval is not a sex with underagers or drugs to get
> berserk on the combination of these four letters by itself, IMHO.

Somewhere on this planet, your village misses you very much.

Signature

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

VK - 29 Nov 2007 20:28 GMT
> > You mean you know a script engine where eval("2") doesn't return
> > typeof "number"?
>
> Who said I did? I didn't. Anybody that uses eval(string) to convert
> string to a number is an incompetent ignorant idiot.

And anyone who uses instead +"2" trick instead is a highly intelligent
experienced master who's even sh** smells just like roses? :-)

Cool... Got it... Some men are so easy to please, really :-)
Randy Webb - 30 Nov 2007 04:48 GMT
VK said the following on 11/29/2007 3:28 PM:
>>> You mean you know a script engine where eval("2") doesn't return
>>> typeof "number"?
[quoted text clipped - 3 lines]
> And anyone who uses instead +"2" trick instead is a highly intelligent
> experienced master who's even sh** smells just like roses? :-)

Your village misses you terribly.
Signature

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

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.