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方法的更多相关文章

  1. js中的tostring()方法

    http://blog.sina.com.cn/s/blog_85c1dc100101bxgg.html js中的tostring()方法 (2013-11-12 11:07:43) 转载▼ 标签: ...

  2. jQuery与JS中的map()方法使用

    1.jquery中的map()方法 首先看一个简单的实例: $("p").append( $("input").map(function(){ return $ ...

  3. js中声明Number的五种方式

    转载自:http://www.jb51.net/article/34191.htm <!DOCTYPE html> <html> <head> <meta c ...

  4. 秒味课堂Angular js笔记------Angular js中的工具方法

    Angular js中的工具方法 angular.isArray angular.isDate angular.isDefined angular.isUndefined angular.isFunc ...

  5. JS中通过call方法实现继承

    原文:JS中通过call方法实现继承 讲解都写在注释里面了,有不对的地方请拍砖,谢谢! <html xmlns="http://www.w3.org/1999/xhtml"& ...

  6. JavaScript -- 时光流逝(二):js中数组的方法

    JavaScript -- 知识点回顾篇(二):js中数组的方法 1. 数组 (1)定义数组,数组赋值 <script type="text/javascript"> ...

  7. ASP.NET#使用母版时,如果要使用js中的getElementById()方法取得某个内容页的元素时要注意的问题

    当使用母版,要使用js中的getElementById()方法取得某个内容页的元素时,所选取的id并不是母版中内容页的id,而是在设计内容页时设定的id例子:母版页: ...... <head ...

  8. JS与OC交互,JS中调用OC方法(获取JSContext的方式)

    最近用到JS和OC原生方法调用的问题,查了许多资料都语焉不详,自己记录一下吧,如果有误欢迎联系我指出. JS中调用OC方法有三种方式: 1.通过获取JSContext的方式直接调用OC方法 2.通过继 ...

  9. JS中split使用方法和数组中元素的删除

    JS中split使用方法和数组中元素的删除 JS中split使用方法 <script language="javascript"> function spli(){ d ...

随机推荐

  1. 【深度学习】ubuntu16.04下安装opencv3.4.0

    1.首先安装一些编译工具 # 安装编译工具 sudo apt-get install build-essential # 安装依赖包 sudo apt-get install cmake git li ...

  2. 动态创建selectjs 操作select和option

    1.动态创建select function createSelect(){ var mySelect = document.createElement("select"); myS ...

  3. finally return 执行关系 异常处理 c#

    Return.finally执行关系简述 除了函数出现system.exit(0)终止虚拟机,finally中的代码一定执行,return语句会等待finally的执行:如果是值传递,finally中 ...

  4. Data Structure Stack: Infix to Postfix

    http://geeksquiz.com/stack-set-2-infix-to-postfix/ #include <iostream> #include <vector> ...

  5. 练习题目 :if for while else range、xrange、zip

    range在内存中直接生成指定的序列,当序列非常大时会浪费内存资源: xrange则不会直接生成一个list,而是每次调用返回其中的一个值,而非直接全部生成存于内存中 range([start,] s ...

  6. Android硬件抽象层(HAL)概要介绍【转】

    本文转载自:http://blog.csdn.net/luoshengyang/article/details/6567257 Android的硬件抽象层,简单来说,就是对Linux内核驱动程序的封装 ...

  7. HDU 1533 Going home

    Going Home Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  8. JsonSchema使用详解

    JSON Schema是一个用于验证JSON数据结构的强大工具, 我查看并学习了JSON Schema的官方文档, 做了详细的记录, 分享一下. 我们可以使用JSON Schema在后续做接口测试中做 ...

  9. Linux Shell文件差集

    file1-file2 => file3file1=/data/aaafile2=/data/bbbfile3=/data/cccsort -m <(sort $file1 | uniq) ...

  10. 算法(Algorithms)第4版 练习 1.4.6

    (1)sum = N + N/2 + N/4 +  …… + 1 假设N是2的倍数(N = 2q),则sum = N -1 ~ N (2)sum = 1+2+……N/2 同(1)分析,sum = N/ ...