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. (转)RequireJS shim 用法说明

    RequireJS中如果使用AMD规范,在使用的过程中没有太多的问题,如果加载非AMD规范的JS文件,就需要使用Require中的shim. require.config({ paths:{ jque ...

  2. python基础9 -----python内置函数2

    一.python内置所以函数     Built-in Functions     abs() divmod() input() open() staticmethod() all() enumera ...

  3. python selenium cookie 登录

    概要: 1.正常登录,使用selenium获取cookie: 2.保存cookie: 3.使用cookie登录. 4.python--2.7,selenium--3.4.1 步骤1 正常登录,使用se ...

  4. Git——基本操作(三)

    一.安装和配置 1.Git安装 yum install git -y 安装完Git就可以对其做一些配置: Git有一个工具被称为git config,它允许你获得和设置配置变量: 这些变量可以控制Gi ...

  5. LeetCode:加一【66】

    LeetCode:加一[66] 题目描述 给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储一个数字. 你可以假设除了整数 0 之外 ...

  6. Java中的 && 与&

    Java中&&和&都是表示与的逻辑运算符,都表示逻辑运输符and,当两边的表达式都为true的时候,整个运算结果才为true,否则为false. &&的短路功能 ...

  7. cmd - - - 随笔

    dxdiag DirectX诊断工具 calc 计算机 cmd里面不想一点点输入冗长的文件路径?直接把这个文件拖到CMD窗口吧!你会发现 路径自己补上去了.有空格的还会自动加引号哟.

  8. js 实现滑块效果

    var dd = $(".drag_bott").removeAttr('id').last().attr('id','drag_bott'); var drag = docume ...

  9. 【leetcode刷题笔记】Anagrams

    Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be ...

  10. 深入理解ES6之迭代器与生成器

    迭代器 迭代器 iterator,在 Javascript 中,迭代器是一个对象(也可称作为迭代器对象),它提供了一个 next() 方法,用来返回迭代序列中的下一项. next 方法的定义,next ...