[thelist] tips

Jeff Howden jeff at jeffhowden.com
Thu Aug 26 15:13:21 CDT 2004


Diane,

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: Diane Soini
> 
> <tip type="Javascript parseInt bug">
> 
> [snip]
> 
> This is a bug in most browsers, but not all.
> Nevertheless, the fix will not hurt anything.
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

Correction.  This is *NOT* a bug.  It is the designed behavior.  It pays to
read the reference material.  To wit:

  "If no radix argument is provided or if it is assigned
   a value of 0, the function tries to determine the
   base. If the string starts with a 1-9, it will be
   parsed as base 10. If the string starts with 0x or 0X
   it will be parsed as a hexidecimal number. If the
   string starts with a 0 it will be parsed as an octal
   number. (Note that just because a number starts with
   a zero, it does not mean that it is really octal.)"

http://www.devguru.com/Technologies/ecmascript/quickref/parseint.html

If you want to override the designed behavior, then specify the optional
radix.  Better yet, consider the radix required in your scripting and you'll
never have this problem.  It's as simple as that.

Jeff
------------------------------------------------------
Jeff Howden - Web Application Specialist
Resume - http://jeffhowden.com/about/resume/
Code Library - http://evolt.jeffhowden.com/jeff/code/




More information about the thelist mailing list