当前位置: 首页 > 图文教程 > 网络编程 > Javascript > js parsefloat parseint 转换函数

Javascript
Add a Table to a Word Document
Add Formatted Text to a Word Document
用jscript实现新建word文档
用jscript实现新建和保存一个word文档
Open and Print a Word Document
Use Word to Search for Files
Convert Seconds To Hours
Sample script that deletes a SQL Server database
Sample script that displays all of the users in a given SQL Server DB
firefox中用javascript实现鼠标位置的定位
div+css实现鼠标放上去,背景跟图片都会变化。
Locate a File Using a File Open Dialog Box
Save a File Using a File Save Dialog Box
用jscript实现列出安装的软件列表
List the Stored Procedures in a SQL Server database
Display SQL Server Login Mode
Display SQL Server Version Information
List all the Databases on a SQL Server
用jscript启动sqlserver
Stop SQL Server

Javascript 中的 js parsefloat parseint 转换函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-02-27   浏览: 478 ::
收藏到网摘: n/a

JavaScript提供了3个显式的类型转换函数,分别是eval()、parseInt()和parseFloat()。 js parsefloat parseint
JavaScript提供了3个显式的类型转换函数,分别是eval()、parseInt()和parseFloat()。
eval()函数:将字符串表达式转换成数字值。例如,语句total=eval("432.1*10")的结果是total=4321即将数值4321赋予total变量。
parseInt()函数:把字符串转换成整数。返回是从字符串的第一个字符开始,如果字符不是以整数开头则返回0。parseInt()函数还可以转换十六进制数或十进制数。
例如:parseInt("123xyz") 返回123,而parseInt("xyz")返回0。
parseFloat()函数:类似于parseInt()函数,它返回字符串上包含的第一个浮点数。如果字符串不以有效浮点数开头,则返回0。
例如:parseFloat("2.1e4xyz")返回21000;而parseFloat("xyz")返回0。
JavaScript中parseFloat函数方法是返回由字符串转换得到的浮点数。 使用方法:
parseFloat(numString)其中numString 参数是包含浮点数的字符串。JavaScript中parseFloat函数方法返回与 numString 中保存的数相等的数字表示。如果 numString 的前缀不能解释为浮点数,则返回 NaN (而不是数字)。
parseFloat("abc") // 返回 NaN。
parseFloat("1.2abc") // 返回 1.2。