js中的Number方法
1.Number.toExponential(fractionDigits)
把number转换成一个指数形式的字符串。可选参数控制其小数点后的数字位数。它必须在0~20之间。
例如:
document.writeln(Math.PI.toExponential(0));
document.writeln(Math.PI.toExponential(2));
document.writeln(Math.PI.toExponential(7));
document.writeln(Math.PI.toExponential(16));
document.writeln(Math.PI.toExponential( )); // Produces 3e+0
3.14e+0
3.1415927e+0
3.1415926535897930e+0
3.141592653589793e+0
2.number.toFixed(fractionDigits)
把number数转换成一个十进制数形式的字符串。可选参数控制其小数点后的数字位数。它的值必须在0~20之间,默认为0,例如:
document.writeln(Math.PI.toFixed(0));
document.writeln(Math.PI.toFixed(2));
document.writeln(Math.PI.toFixed(7));
document.writeln(Math.PI.toFixed(16));
document.writeln(Math.PI.toFixed( )); // Produces 3
3.14
3.1415927
3.1415926535897930
3
3.number.toPrecision(precision)
把这个number转化为一个十进制形式的字符串。可选参数控制字符精度,它的精度必须在0~21之间。例如:
document.writeln(Math.PI.toPrecision(2));
document.writeln(Math.PI.toPrecision(7));
document.writeln(Math.PI.toPrecision(16));
document.writeln(Math.PI.toPrecision( )); // Produces 3.1
3.141593
3.141592653589793
3.141592653589793
4.number.toString(radix)
将number转换成一个字符串。可选参数控制基数,它的值必须在2~36之间。默认radix的值是10。radix参数最常用的是整数,但是它可以用任意数字。
在最普通的情况下,该方法可以写成String(number)
例如:
document.writeln(Math.PI.toString(2));
document.writeln(Math.PI.toString(8));
document.writeln(Math.PI.toString(16));
document.writeln(Math.PI.toString( )); // Produces 11.001001000011111101101010100010001000010110100011
3.1103755242102643
3.243f6a8885a3
3.141592653589793
js中的Number方法的更多相关文章
- js中的tostring()方法
http://blog.sina.com.cn/s/blog_85c1dc100101bxgg.html js中的tostring()方法 (2013-11-12 11:07:43) 转载▼ 标签: ...
- jQuery与JS中的map()方法使用
1.jquery中的map()方法 首先看一个简单的实例: $("p").append( $("input").map(function(){ return $ ...
- js中声明Number的五种方式
转载自:http://www.jb51.net/article/34191.htm <!DOCTYPE html> <html> <head> <meta c ...
- 秒味课堂Angular js笔记------Angular js中的工具方法
Angular js中的工具方法 angular.isArray angular.isDate angular.isDefined angular.isUndefined angular.isFunc ...
- JS中通过call方法实现继承
原文:JS中通过call方法实现继承 讲解都写在注释里面了,有不对的地方请拍砖,谢谢! <html xmlns="http://www.w3.org/1999/xhtml"& ...
- JavaScript -- 时光流逝(二):js中数组的方法
JavaScript -- 知识点回顾篇(二):js中数组的方法 1. 数组 (1)定义数组,数组赋值 <script type="text/javascript"> ...
- ASP.NET#使用母版时,如果要使用js中的getElementById()方法取得某个内容页的元素时要注意的问题
当使用母版,要使用js中的getElementById()方法取得某个内容页的元素时,所选取的id并不是母版中内容页的id,而是在设计内容页时设定的id例子:母版页: ...... <head ...
- JS与OC交互,JS中调用OC方法(获取JSContext的方式)
最近用到JS和OC原生方法调用的问题,查了许多资料都语焉不详,自己记录一下吧,如果有误欢迎联系我指出. JS中调用OC方法有三种方式: 1.通过获取JSContext的方式直接调用OC方法 2.通过继 ...
- JS中split使用方法和数组中元素的删除
JS中split使用方法和数组中元素的删除 JS中split使用方法 <script language="javascript"> function spli(){ d ...
随机推荐
- MainWindows
开发带有菜单栏状态栏等常用windows应用时候使用
- HTML 5 本地存储
<!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...
- 3.16课·········C#小结
//附加//C#源码,被C#编译器,编译成执念代码(IL)//int16=short.....±32000//int32=int.......±21亿//int64=long......±922亿亿3 ...
- nodejs之入门
一.安装: 去官网下载稳定版本,安装即可. 安装后执行node -v,显示node版本,然后输入node回车,然后输出console.log(111);,正常输出即可. 二.入门介绍: 1.nodej ...
- 0420模块 序列化模块 hashlib模块
复习:内置方法 __len__ len(obj)的结果依赖于obj.__len__()的结果,计算对象的长度__hash__ hash(obj)的结果依赖于obj.__hash__()的结果,计算对象 ...
- linux基本使用
(待完善,想到哪就写到哪,目前内容大幅度参考中文man手册) 最重要的命令(man) 在 Linux 下遇到问题,最重要的是要自己寻求帮助, google是个好东西 man 是 Linux 的帮助手册 ...
- 51nod1613
题意:给定n个正面朝上的硬币,每次可以翻转k个硬币,求至少多少次翻转能使之全部反面朝上. 神犇题解 我真的吐槽不能了..这题能做?! 极其复杂的分类讨论..膜拜这位爷.
- Ubuntu忘记用户密码解决方法--Authentication token manipulation error
1.重启系统,按住shift键进入grub菜单: 2.选择recovery mode恢复模式: 3.在recovery menu中选择root drop to root shell prompt: 4 ...
- cpu架构
转自 http://blog.csdn.net/wyzxg/article/details/5027738 CPU架构 Architecture ,结构.架构,这个词用于 CPU 的时候是指 CPU ...
- php把字符串指定字符分割成数组
<?php $str="1|2|3|4|5|"; $var=explode("|",$str); print_r($var); ?> $var=ex ...