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

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 js parsefloat parseint 转换函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-02-27   浏览: 479 ::
收藏到网摘: 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。