Math.floor只能对一个数向下取整,不能解析字符串

如:

Math.floor(1.5) // 1

Math.floor(-2.1) // -3

Math.floor("3")  // 3

Math.floor('Hello') // NaN

Math.floor('16岁') // NaN

parseInt(string, radix)可将任意数字开头字符串转换为相应整数,后一个参数表进制,可取值2/8/10/16,默认是十进制

如:

parseInt(1.5) // 2

parseInt(1.2) // 1

parseInt(-2.1) // -2

parseInt('3') // 3

parseInt('hello')  // NaN

parseInot('16岁') // 16

基础-Math.floor与parseInt区别的更多相关文章

  1. Javascript -- Math.round()、Math.ceil()、Math.floor()、parseInt去小数取整总结

    一.Math.round() 作用:四舍五入返回整数.(返回参数+0.5后,向下取整) Math.round(5.57) //返回6 Math.round(2.4) //返回2 Math.round( ...

  2. Math.floor() 与 parseInt()

    parseInt()与Math.floor()都能实现数字的向下取整,但是两者存在根本上的差异,1.Math.floor()用于一个数的向下取整,不能解析字符串 <script type=&qu ...

  3. Number(),parseInt(),parseFloat(),Math.round(),Math.floor(),Math.ceil()对比横评

    首先,这些处理方法可分为三类. 1,只用来处理数字取整问题的:Math.round(),Math.floor(),Math.ceil(): 2,专门用于把字符串转化成数值:parseInt(),par ...

  4. js中Math.round、parseInt、Math.floor和Math.ceil小数取整小结

    以前经常在代码中看到Math.round.parseInt.Math.floor和Math.ceil这四个函数,虽然知道结果都可以返回一个整数,但是对他们四者的区别还是不太清楚,今天就做一个小结. 一 ...

  5. js中Math.round、parseInt、Math.floor和Math.ceil小数取整小结【转】

    [摘要:之前常常正在代码中看到Math.round.parseInt.Math.floor战Math.ceil那四个函数,固然晓得效果皆能够返回一个整数,然则对他们四者的差别照样没有太清晰,本日便做一 ...

  6. js中Math.round、parseInt、Math.floor和Math.ceil小数取整总结

    Math.round.parseInt.Math.floor和Math.ceil 都可以返回一个整数,具体的区别请看下面的总结. 一.Math.round 作用:四舍五入,返回参数+0.5后,向下取整 ...

  7. js中Math.round、parseInt、Math.floor和Math.ceil小数取整总结(转)

    js中Math.round.parseInt.Math.floor和Math.ceil小数取整总结 Math.round.parseInt.Math.floor和Math.ceil 都可以返回一个整数 ...

  8. Javascript Math.ceil()与Math.round()与Math.floor()区别

    Math.ceil()向上舍入 1 2 3 alert(Math.ceil(20.1)) //输出 21 alert(Math.ceil(20.5)) //输出 21 alert(Math.ceil( ...

  9. Math.round()、Math.ceil()、Math.floor()与Math.random()的区别?

    Math.round(x) 四舍五入 加上0.5向下取整 Math.round(1.5) 2 Math.round(-11.5) -11 Math.round(-11.2) -10 Math.ceil ...

随机推荐

  1. GUI练习3

    将阿里山的积分卡拉斯的发生的咖啡机啊圣考虑到发送到敬爱费卢卡斯加

  2. C# X509Certificate类 调用证书

    一.命名空间 using System.Security.Cryptography.X509Certificates; 二.调用代码 string certPath = Server.MapPath( ...

  3. nginx跟apache访问方法

    ifconfig 在浏览器中输入ip即可访问 centos安装nginx环境 1:进入 cd /usr/local/src  //下载文件放到这个目录中 2:wget http://nginx.org ...

  4. Python高级网络编程系列之终极篇---自己实现一个Web框架

    通过前面几个小节的学习,现在我们想要把之前学到的知识点给串联起来,实现一个很小型的Web框架.虽然很小,但是用到的知识点都是比较多的.如Socket编程,装饰器传参在实际项目中如何使用.通过这一节的学 ...

  5. 转载 javascript中(function($){...})(jQuery)写法是什么意思

    javascript中(function($){...})(jQuery)写法是什么意思   这里实际上是匿名函数function(arg){...}这就定义了一个匿名函数,参数为arg 而调用函数 ...

  6. 《深入理解Java虚拟机》笔记(转)

    文章来自http://www.cnblogs.com/tianchi/archive/2012/11/11/2761631.html 在C里面我们想执行一段自己编写的机器指令的方法大概如下: type ...

  7. solvepnp

    CV_EXPORTS_W bool solvePnP( InputArray objectPoints,- 世界坐标系下的控制点的坐标,vector<Point3f>的数据类型在这里可以使 ...

  8. ubuntu14.04下播放器SMplayer的安装

    1. Mplayer 与 SMplayer的区别 虽然MPlayer播放器是人类史上最强大的播放器(参数超过千个),但是其默认编译没有界面,所以写参数时间甚至比看片时间还长.虽然编译时候可以选择--e ...

  9. mysql分表操作

    一般分表操作有垂直拆分和水平拆分.顾名思义. 1.  垂直拆分是指,这个表的列,即字段,要拆分成两个或多个表. 这个应用场景比如:这个表字段,几个都是int.datetime等,有那么一个是text类 ...

  10. VB6 加密解密字符串

    Public Function EnCodeStr(ByVal password As String) As String Dim il_bit, il_x, il_y, il_z, il_len, ...