Number 数据类型
//Number 数据类型
//包含 整数 小数 NaN(not a number)
var a = 1233;
var b = 12.34;
//1/'a'
//把其他数据类型转化成数字,他在转化时,只要字符里边有非数字,就会转成NaN
Number() // ---> 把其他数据类型
// console.log(Number(.5));// 0.5
// console.log(Number('.5'));// 0.5
// console.log(Number('')); // 0
// console.log(Number(' '));// 0
// console.log(Number('12q'));// NaN
// console.log(Number());// 0
// console.log(Number(false));// 0
// console.log(Number(true));// 1
// console.log(Number([])); // 0
// console.log(Number({})); // NaN
// console.log(Number(null)); // 0
// console.log(Number(undefined));// NaN //把浮点型转化成 整型
//parseInt()
console.log(parseInt('1.3q'));
console.log(parseInt('12q.3'));
//parseInt('')-->NaN
console.log(parseInt('.5'))//NaN
console.log(parseInt('0.5'));//0
console.log(parseInt(.5));//0
console.log(parseInt('q12'))//NaN
// console.log(parseInt(1.9)); //parseFloat()
console.log(parseFloat('.5q'))
console.log(parseFloat(1.8)) // Number(undefined) == NaN ===> NaN == NaN ==> false isNaN(parseInt(''))// parseInt('') --> NaN isNaN(NaN) -- >true isNaN('') //-- >false
isNaN([]) // --> false []--->0 isNaN(0)
isNaN(undefined)// true // - / * % 先把非数字用Number转化成数字 在进行运算
1/'q' // ---> NaN
1/'1' // ---> 1
1*'1.2'// ---> 1.2
1*'1.2a'// ---> NaN
1*'q' // ---> NaN // + 两边都是数字类型,那就是正常的加法运算
// 假如 连边有一边时字符串, 那就是字符串拼接
1 + 2 * 2 - 1 + 'a';
'a' + 2 - 3 * 2 + 1;// --> "a" + 2 - 6 + 1 -- > "a2" - 6 + 1==> NaN
isNaN('a' + 2 ) - '2' + parseInt('2.5a') ;
// isNaN('a2') - '2' + 2;
// isNaN(NaN) - '2' + 2;
// true - '2' + 2;
// 1 - 2 + 2 == > 1
Number 数据类型的更多相关文章
- number 数据类型的分析。
在js中,number数据类型可能算最令人关注的的类型之一了. number类型分为整数和浮点数. 一,整型数,整型又分为十进制,八进制,十六进制. 十进制即是生活中接触到的:而八进制数的首位必须是零 ...
- (转载)Flash Number 数据类型
(转载)http://www.g168.net/txt/flash/learningactionscript/00001183.html Number 数据类型 Number 数据类型是双精度浮点数. ...
- 关于容器类型数据的强转一共:str() list() set() tuple() dict() 都可以转换成对应的数据类型 /Number 数据类型的强转一共: int() bool() flaot() complex() 都可以转换成对应的数据类型
# ###强制转换成字典类型 # 多级容器数据:该类型是容器数据,并且里面的元素还是容器类型数据 # ###二级容器 # 二级列表 listvar = [1,3,4,5,[6,7,8,9]] res ...
- python自动类型转换(针对于Number数据类型来的)精度从低到高 bool->int-> float->complex 当两个不同是数据类型运算时候,默认想更高进度转化
# ### 自动类型转换(针对于Number数据类型来的) ''' 精度从低到高 bool->int-> float->complex 当两个不同是数据类型运算时候,默认想更高进度转 ...
- JS中的Number数据类型详解
Number数据类型 Number类型使用IEEE754格式来表示整数和浮点值,这也是0.2 + 0.3不等于0.5的原因, 最基本的数值类型字面量格式是十进制整数 var a = 10; 1. 浮点 ...
- 【转】oracle数据库NUMBER数据类型
原文:http://www.jb51.net/article/37633.htm NUMBER ( precision, scale)a) precision表示数字中的有效位;如果没有指定prec ...
- Oracle的number数据类型
https://www.cnblogs.com/oumyye/p/4448656.html NUMBER ( precision, scale) precision表示数字中的有效位;如果没有指定pr ...
- oracle中number数据类型简单明了解释
NUMBER (p,s) p和s范围: p 1-38 s -84-127 number(p,s),s大于0,表示有效位最大为p,小数位最多为s,小数点右边s位置开始四舍五入,若s>p,小数点右侧 ...
- oracle 的number数据类型
NUMBER类型细讲:Oracle number datatype 语法:NUMBER[(precision [, scale])]简称:precision --> p scale ...
随机推荐
- Delphi中SendMessage使用说明(所有消息说明) good
Delphi中SendMessage使用说明 SendMessage基础知识 函数功能:该函数将指定的消息发送到一个或多个窗口.此函数为指定的窗口调用窗口程序,直到窗口程序处理完消息再返回.而函数Po ...
- SpringMVC_RESTRUL_CRUD
编写POJO Departmet: package org.springmvc.curd.entity; public class Department { private int id; priva ...
- fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt
project->xx Properties->Manifest->Input and Output->Embed Manifest将yes修改为no
- js中return的作用及用法
这里面的return含有一些细节知识: 例如:onClick='return add_onclick()'与 onClick='add_onclick()'的区别 JAVASCRIPT在事件中调用函数 ...
- codevs1297 硬币(背包dp,方案数)
1297 硬币 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 我们知道即使是同一种面值的硬币,它们的重量也有可能不一样, ...
- RandomAccessFile使用场景及总结
大家在学到Java中IO流的时候学到了各种流,对文件的各种操作.但是唯独可能对RandomAccessFile对象不会去过多的研究,那么这个到底有什么用呢? RandomAccessFile的唯一父类 ...
- [LOJ#10132]异象石
Description Adera 是 Microsoft 应用商店中的一款解谜游戏. 异象石是进入 Adera 中异时空的引导物,在 Adera 的异时空中有一张地图.这张地图上 有 N 个点,有 ...
- 莫队算法/二分查找 FZU 2072 Count
题目传送门 题意:问区间内x的出现的次数分析:莫队算法:用一个cnt记录x的次数就可以了.还有二分查找的方法 代码: #include <cstdio> #include <algo ...
- N - Binomial Showdown (组合数学)
Description In how many ways can you choose k elements out of n elements, not taking order into acco ...
- Canvas入门笔记-实现极简画笔
今天学习了Html5 Canvas入门,已经有大神写得很详细了http://www.cnblogs.com/tim-li/archive/2012/08/06/2580252.html#8 在学习过后 ...