zoukankan      html  css  js  c++  java
  • js中的Number方法

    1.Number.toExponential(fractionDigits)

    把number转换成一个指数形式的字符串。可选参数控制其小数点后的数字位数。它必须在0~20之间。

    例如:

     1 document.writeln(Math.PI.toExponential(0));
     2 document.writeln(Math.PI.toExponential(2));
     3 document.writeln(Math.PI.toExponential(7));
     4 document.writeln(Math.PI.toExponential(16));
     5 document.writeln(Math.PI.toExponential(  ));
     6 
     7 // Produces
     8 
     9 3e+0
    10 3.14e+0
    11 3.1415927e+0
    12 3.1415926535897930e+0
    13 3.141592653589793e+0

    2.number.toFixed(fractionDigits)

    把number数转换成一个十进制数形式的字符串。可选参数控制其小数点后的数字位数。它的值必须在0~20之间,默认为0,例如:

     1 document.writeln(Math.PI.toFixed(0));
     2 document.writeln(Math.PI.toFixed(2));
     3 document.writeln(Math.PI.toFixed(7));
     4 document.writeln(Math.PI.toFixed(16));
     5 document.writeln(Math.PI.toFixed(  ));
     6 
     7 // Produces
     8 
     9 3
    10 3.14
    11 3.1415927
    12 3.1415926535897930
    13 3

    3.number.toPrecision(precision)

    把这个number转化为一个十进制形式的字符串。可选参数控制字符精度,它的精度必须在0~21之间。例如:

     1 document.writeln(Math.PI.toPrecision(2));
     2 document.writeln(Math.PI.toPrecision(7));
     3 document.writeln(Math.PI.toPrecision(16));
     4 document.writeln(Math.PI.toPrecision(  ));
     5 
     6 // Produces
     7 
     8 3.1
     9 3.141593
    10 3.141592653589793
    11 3.141592653589793

    4.number.toString(radix)

    将number转换成一个字符串。可选参数控制基数,它的值必须在2~36之间。默认radix的值是10。radix参数最常用的是整数,但是它可以用任意数字。

    在最普通的情况下,该方法可以写成String(number)

    例如:

     1 document.writeln(Math.PI.toString(2));
     2 document.writeln(Math.PI.toString(8));
     3 document.writeln(Math.PI.toString(16));
     4 document.writeln(Math.PI.toString(  ));
     5 
     6 // Produces
     7 
     8 11.001001000011111101101010100010001000010110100011
     9 3.1103755242102643
    10 3.243f6a8885a3
    11 3.141592653589793
  • 相关阅读:
    https页面打不开
    Centos6.5安装步骤(U盘安装)
    利用Metrics+influxdb+grafana构建监控平台
    CentOS 7安装Oracle 11gR2以及设置自启动
    如何安装Oracle Instant Client
    (转)rlwrap真是一个好东西
    oracle数据库11g(11.2.0.1)安装报错:提示ins_ctx.mk编译错误。
    oracle查看所有表及各表行数
    dp hdu5653 xiaoxin and his watermelon candy
    C语言free函数的原理——————————【Badboy】
  • 原文地址:https://www.cnblogs.com/yangxiaoguai132/p/5268184.html
Copyright © 2011-2022 走看看