基礎-Math.floor與parseInt區別

Math.floor只能對一個數向下取整,不能解析字符串字符串

如:string

Math.floor(1.5) // 1di

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

相關文章
相關標籤/搜索