Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Number to string??

Reply
Thread Tools

Number to string??

 
 
Mike
Guest
Posts: n/a
 
      11-28-2007
Why is this converted to a string???
var newidNumber =((idNumber/2).toFixed())+1;

Thanks
Mike
 
Reply With Quote
 
 
 
 
Henry
Guest
Posts: n/a
 
      11-28-2007
On Nov 28, 4:35 pm, Mike <ampel...@gmail.com> wrote:
> Why is this converted to a string???
> var newidNumber =((idNumber/2).toFixed())+1;


Because the - toFixed - method returns a string.
 
Reply With Quote
 
 
 
 
kendalk08
Guest
Posts: n/a
 
      11-28-2007
On Nov 28, 10:37 am, Henry <rcornf...@raindrop.co.uk> wrote:
> On Nov 28, 4:35 pm, Mike <ampel...@gmail.com> wrote:
>
> > 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
 
Reply With Quote
 
Henry
Guest
Posts: n/a
 
      11-28-2007
On Nov 28, 4:45 pm, kendalk08 <kendal...@gmail.com> wrote:
> On Nov 28, 10:37 am, Henry <rcornf...@raindrop.co.uk> wrote:
>
> > On Nov 28, 4:35 pm, Mike <ampel...@gmail.com> wrote:

>
> > > 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


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.
 
Reply With Quote
 
kendalk08
Guest
Posts: n/a
 
      11-28-2007
On Nov 28, 10:56 am, Henry <rcornf...@raindrop.co.uk> wrote:
> On Nov 28, 4:45 pm, kendalk08 <kendal...@gmail.com> wrote:
>
> > On Nov 28, 10:37 am, Henry <rcornf...@raindrop.co.uk> wrote:

>
> > > On Nov 28, 4:35 pm, Mike <ampel...@gmail.com> wrote:

>
> > > > 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

>
> 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.


You probably know more about Javascript, but I have been coding for
about 2 years and the - eval - function has always worked for me.
 
Reply With Quote
 
Henry
Guest
Posts: n/a
 
      11-28-2007
On Nov 28, 4:57 pm, kendalk08 wrote:
> On Nov 28, 10:56 am, Henry wrote:

<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.
 
Reply With Quote
 
nolo contendere
Guest
Posts: n/a
 
      11-28-2007
On Nov 28, 12:06 pm, Henry <rcornf...@raindrop.co.uk> wrote:
> On Nov 28, 4:57 pm, kendalk08 wrote:
>
> > On Nov 28, 10:56 am, Henry wrote:

> <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".
>


There are such things as manners--this sentence was probably
unnecessary.
 
Reply With Quote
 
VK
Guest
Posts: n/a
 
      11-29-2007
On Nov 29, 3:00 am, Randy Webb <HikksNotAtH...@aol.com> wrote:
> kendalk08 said the following on 11/28/2007 11:45 AM:
>
> > On Nov 28, 10:37 am, Henry <rcornf...@raindrop.co.uk> wrote:
> >> On Nov 28, 4:35 pm, Mike <ampel...@gmail.com> wrote:

>
> >>> 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?


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.
 
Reply With Quote
 
VK
Guest
Posts: n/a
 
      11-29-2007
On Nov 29, 12:25 pm, Randy Webb <HikksNotAtH...@aol.com> wrote:
> > 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
OT: Number Nine, Number Nine, Number Nine FrisbeeŽ MCSE 37 09-26-2005 04:06 PM
The number name 'System.Web.UI.WebControls' contains more than the maximum number of prefixes. The maximum is 3. mayur ASP .Net 2 07-02-2004 10:35 AM
real number to 16 bit signed number hari VHDL 6 05-02-2004 04:10 PM
IE 6.0 sockets number (TCP/IP channels number) for the same Site ??? taras ASP .Net 1 04-17-2004 04:51 AM
Convert decimal number in binary number makok VHDL 1 02-23-2004 06:04 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57