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 ...
随机推荐
- python基础9 -----python内置函数2
一.python内置所以函数 Built-in Functions abs() divmod() input() open() staticmethod() all() enumera ...
- js常用方法(。。。。不完整)
lastIndexOf();substring();split();slice();splice(); var s="http://www.baidu.com"; var unit ...
- 基于socket实现上传文件
基于socket实现文件上传 客户端代码: #!/usr/bin/env python # -*- coding:utf-8 -*- """ 这个是实现上传文件 首先让客 ...
- 次小生成树 POJ 2728
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>us ...
- EntityFramework 学习 一 Add New Entity using DBContext in Disconnected Scenario
using System; using System.Collections.Generic; public partial class Student { public Student() { th ...
- python中字符串使用需要注意的地方
1. r''的使用 'r'是防止字符转义的 如果路径中出现'\t'的话 不加r的话\t就会被转义 而加了'r'之后'\t'就能保留原有的样子 2. u''的使用 引号之前加上字母u时,python会将 ...
- wget下载文件
http://blog.sina.com.cn/s/blog_4af3f0d20100n1k0.html 一.下载目录 #wget -r -np -nd http://example.com/pack ...
- Linux- 运维
Linux运维遇到需要使用命令 查看Linux系统有多少用户 cat /etc/passwd | wc -l 查看用户占用的uid,默认情况下,ldap新增的用户和系统本地的用户uid是混在一起.在新 ...
- POJ 2421 Constructing Roads(Kruskal算法)
题意:给出n个村庄之间的距离,再给出已经连通起来了的村庄.求把所有的村庄都连通要修路的长度的最小值. 思路:Kruskal算法 课本代码: //Kruskal算法 #include<iostre ...
- spring MVC--配置注解
<context-param> 作用:该元素用来声明应用范围(整个WEB项目)内的上下文初始化参数 param-name 设定上下文的参数名称.必须是唯一名称 param-value 设定 ...