zoukankan      html  css  js  c++  java
  • How to "round" numbers

    There is a versatile function in Ax to perform rounding operations: round.
    This function rounds the first real argument to the nearest multiple of the second real argument. So plenty of possibilities, for example

    round ( 1.2 , 1) equals 1
    round ( 1.2 , 5) equals 0
    round ( 6.4 , 5) equals 5
    round ( 7.5 , 5) equals 10
    round ( 1.2 , 0.5) equals 1
    round ( 1.12 , 0.1) equals 1.1

    If you don't want to work with the multiples of the second argument and instead just want to specify a number of decimals places to round, you can use decround.
    This functions rounds the first real argument to the number of decimals specified (second argument). So for example

    decround (1.2 , 0) equals 1
    decround (1.23 , 0) equals 1
    decround (1.23 , 1) equals 1.2
    decround (1.25 , 1) equals 1.3

    But the second argument can be negative as well. Like this:

    decround (123, -2) equals 100


    Now for rounding with a little twist: roundup.

    If you want to round a number up to the next real value, you can use roundup. This function is the same as the ceiling function from other environments.
    Same format as the previous round functions, needing 2 arguments.
    So for example

    roundup ( 1.23 , 0.1) give as result 1.3
    roundup ( 123 , 5) equals 125
    roundup ( 123.23 , 5) equals 125
    roundup ( 123.23 , 1) equals 124

    If that ain't enough, more rounding functions: rounddown and roundzero.
    Rounddown rounds your real value always down to the multiple of your second argument.
    While roundzero, as the function name says, rounds towards zero.
    The difference you can see in the next example:

    rounddown (-9 , 5) equals -10
    roundzero (-9 , 5) equals -5

     

    Jobs with Jimmy_round

    static void Jimmy_round(Args _args)
    {
    ;
        print roundUp(26, 5);//26 / 5 = 5.2(6 * 5 unit = 30)直接小数进位加1×单位差
        print 26/5;
        print round(10,4);//(10/4 = 2.5(3 * 4unit = 12)四舍五入×单位差
        print global::roundDown(10,4);//(10/4 = 2.5(2 * 4unit = 8))直接无视小数位×单位差
        print global::roundUpDec(10,4);//右移4位即0.0001,roundUp(10,0.0001) = 10 / 0.0001 *
        print roundUp(10,0.0001);//10 / 0.0001 = 10000,100000 * 0.0001 = 10
        print round(10,1.2);//10 / 1.2 = 8.3 , 8 * 1.2 = 9.6
    
    
        print    rounddown(12.86,5);//10
        print    roundup(12.86,5);//15
        print    rounddown(-9.1,-1);//-9
        print    rounddown(-9.1,1);//-10
        print    roundzero(-9,1);//-9
        print    roundzero(14.16,5);//10
    
        print    frac(12.86);//0.86 截取小数部分
        print    trunc(12.86);//12.00截取整数部分
    
        pause;
    
    }
    

  • 相关阅读:
    java计算组合数
    编写一个方法,使用以上算法生成指定数目(比如1000个)的随机整数
    不用static,巧用对象.方法调用java中的函数
    主函数调用相同函数名的小知识
    poj 3608 旋转卡壳求不相交凸包最近距离;
    UVa1453或La4728 凸包+枚举(或旋转卡壳)
    hdu4666 最远曼哈顿距离
    poj2926 曼哈顿最远距离
    poj 2187 凸包加旋转卡壳算法
    UVa 10256 凸包简单应用
  • 原文地址:https://www.cnblogs.com/Fandyx/p/1790424.html
Copyright © 2011-2022 走看看