Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 13th, 2006, 07:36 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default Number or parseFloat

Code:
noa = Number(df.noa.value);
or
Code:
noa = parseFloat(df.noa.value);
Which is the best to use here?

Picco


www.crmpicco.co.uk
__________________
_______________________
Ayrshire Minis - a Mini E-Community
http://www.ayrshireminis.com
http://www.crmpicco.co.uk
 
Old January 18th, 2006, 07:51 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii crmpicco!!!
In my case i use Number
since
 parseFloat ->First character can be("." ,"+","-")or any number(0-9)
             If it finds a character other than these (say at point p),it ignores that character and all succeeding characters and return the value up to that point P.

so whenever any non numeric number (say a,~,;) found in the parameter value it discarded from that location
e.g
a="-23.,34g" //or when form field contains (-23.,34g) as a input value
parseFloat(a) will return -23
a="2w3.34g" will return only 2
a="23g23" will give only 23

The same thing with parseInt
if first argument is started with "0x" it assumes it's a
hexadecimal value.
if started with 0 - not followed by an "x" - assumes as a octal value
so to avoid these problems use parseInt(string [,radix])


Hope this will help you


Cheers :)

vinod
 
Old January 18th, 2006, 10:05 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

thanks Vinod, i'll be sure to use Number(var) from now on.............

www.crmpicco.co.uk
 
Old January 18th, 2006, 12:25 PM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

which is heavier on processing? I dont have many occurancies in my script, but would like to know if Number causes the same "Compiler" problem as eval for example

www.crmpicco.co.uk
 
Old January 19th, 2006, 12:42 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii Crmpicco!!!
 I use regular expressions to check for valid number,float,negative numbers.
Offcourse regular expression executes faster,I think so.

Hope this will help you



Cheers :)

vinod
 
Old March 21st, 2006, 01:03 PM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

Quote:
quote:parseInt(string [,radix])
you mention radix? is this an 'option'?

www.crmpicco.co.uk
 
Old March 21st, 2006, 01:18 PM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You should always specify radix when using parseInt otherwise you can get some strange results with "09" etc.
personally for integers I use Math.floor().

--

Joe (Microsoft MVP - XML)




Similar Threads
Thread Thread Starter Forum Replies Last Post
Validation For Phone Number and Mobile Number dhruthi.ram99 Javascript How-To 12 October 30th, 2011 07:24 AM
Problem with JavaScript function parseFloat parthi_vep Javascript 3 May 26th, 2008 07:49 AM
get the DDR number yanis97 J2EE 0 August 23rd, 2005 11:17 AM
number pixel Perseus Beginning VB 6 1 August 11th, 2005 05:08 PM
number? crmpicco Classic ASP Basics 2 June 10th, 2005 05:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.