javascript手冊-p&q[2]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 longj 的 blog

  • 0 on windows platforms.
  • "nan" on any other platform, indicating that the value is not a number.

    for arithmetic purposes, the "nan" value is not a number in any radix. you can call the isnan function to determine if the result of parsefloat is "nan". if "nan" is passed on to arithmetic operations, the operation results will also be "nan".

    例子

    the following 例子 all return 3.14:

    parsefloat("3.14")
    parsefloat("314e-2")
    parsefloat("0.0314e+2")
    var x = "3.14"
    parsefloat(x)
    

    the following example returns "nan" or 0:

    parsefloat("ff2")
    

    相关

  • isnan, parseint functions

    parseint function

    parses a string argument and returns an integer of the specified radix or base.

    语法

    parseint(string [,radix])

    string is a string that represents the value you want to parse.
    radix is an integer that represents the radix of the return value.

    description

    the parseint function is a built-in javascript function. it is not a method associated with any object, but is part of the language itself.

    the parseint function parses its first argument, a string, and attempts to return an integer of the specified radix (base). for example, a radix of 10 indicates to convert to a decimal number, 8 octal, 16 hexadecimal, and so on. for radixes above 10, the letters of the alphabet indicate numerals greater than 9. for example, for hexadecimal numbers (base 16), a through f are used.

    if parseint encounters a character that is not a numeral in the specified radix, it ignores it and all succeeding characters and returns the integer value parsed up to that point. parseint truncates numbers to integer values.

    if the radix is not specified or is specified as 0, javascript assumes the following:

  • if the input string begins with "0x", the radix is 16 (hexadecimal).
  • if the input string begins with "0", the radix is 8 (octal).
  • if the input string begins with any other value, the radix is 10 (decimal).

    if the first character cannot be converted to a number, parsefloat returns one of the following values:

  • 0 on windows platforms.
  • "nan" on any other platform, indicating that the value is not a number.

    for arithmetic purposes, the "nan" value is not a number in any radix. you can call the isnan function to determine if the result of parseint is "nan". if "nan" is passed on to arithmetic operations, the operation results will also be "nan".

    例子

    the following 例子 all return 15:

    parseint("f", 16)
    parseint("17", 8)
    parseint("15", 10)
    parseint(15.99, 10)
    parseint("fxx123", 16)
    parseint("1111", 2)
    parseint("15*3", 10)
    

    the following 例子 all return "nan" or 0:

    parseint("hello", 8)
    parseint("0x7", 10)
    parseint("fff", 10)
    

    even though the radix is specified differently, the following 例子 all return 17 because the input string begins with "0x".

    parseint("0x11", 16)
    parseint("0x11", 0)
    parseint("0x11")
    

    相关

  • isnan, parsefloat functions

    password object

    a text field on an htm form that conceals its value by displaying asterisks (*). when the user enters text into the field, asterisks (*) hide anything entered from view.

    语法

    to define a password object, use standard htm 语法:

    <input
       type="password"
       name="passwordname"
       [value="textvalue"]
       size=integer>
    
    name="passwordname" specifies the name of the password object. you can access this value using the name property.
    value="textvalue" specifies the initial value of the password object. you can access this value using the defaultvalue property.

  • 本文关键:javascript
      相关方案
    Google
     

    本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

    go top