zoukankan      html  css  js  c++  java
  • js fix小数点 和int的区别

    num.Fixed(2)

    功能:可以定义精确到多少为的小数点。

    Returns the integer portion of a number.


    Int(number)



    Fix(number)

    The number argument can be any valid numeric expression. If number contains Null, Null is returned.

    Both Int and Fix remove the fractional part of number and return the resulting integer value.

    The difference between Int and Fix is that if number is negative, Int returns the first negative integer less than or equal to number, whereas Fix returns the first negative integer greater than or equal to number. For example, Int converts -8.4 to -9, and Fix converts -8.4 to -8.

    The following examples illustrate how the Int and Fix functions return integer portions of numbers:

      CopyCode imageCopy Code
    MyNumber = Int(99.8)    ' Returns 99.



    MyNumber = Fix(99.2) ' Returns 99.



    MyNumber = Int(-99.8) ' Returns -100.



    MyNumber = Fix(-99.8) ' Returns -99.



    MyNumber = Int(-99.2) ' Returns -100.



    MyNumber = Fix(-99.2) ' Returns -99.

    经过测试 结论:  在netsuite中 不能使用 num.Fixed(2)  必须使用num.toFixed(2)  才可以成功.  所以,默认这个版本的js 支持: toFixed

    这里还需要注意一点 由于js是不明确定义变量的类型,所有我们在用一个数左右一个自定义函数的返回值时,需要对它进行类型的转化后 才可以使用 toFixed方法。

    parseFloat  这个时候就派上用场了。  先parseFloat 在toFixed(4),即可。

  • 相关阅读:
    linux系统之tr命令
    Tmux会话-基本操作及原理
    [题解] P1552 [APIO2012]派遣
    数论学习笔记
    Splay 学习笔记
    SpringCloud---入门篇(1)
    获小黄杉有感
    2020湖湘杯-CRYPTO-简单的密码3 WriteUp (CBC字节翻转)
    ECC椭圆曲线加密算法—加解密(SageMath实现)
    栅栏密码&W型栅栏密码-加解密(python实现)
  • 原文地址:https://www.cnblogs.com/backuper/p/1311304.html
Copyright © 2011-2022 走看看