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),即可。

  • 相关阅读:
    MySQL 5.7.18 zip 文件安装过程
    Mysql 自定义随机字符串
    JAVA基本类型和引用类型
    初识JSP
    Java导出错误数据
    时序图的使用习惯
    Redis踩坑
    ES踩坑
    代码规范
    Git在公司的使用流程
  • 原文地址:https://www.cnblogs.com/backuper/p/1311304.html
Copyright © 2011-2022 走看看