GDK为数字提供的方法

    技术2026-08-19  19

    1/7的结果是BigDecimal,0.1428571429这是四舍五入的结果,而不是像java一样结果为0

     

    abs toInteger round方法

    除此之外

    还提供了以闭包为参数的方法

    times upto downto step

     

    //times用于重复做一件事情

    10.times{do something}

    //

    sum=''

    1.upto(10){number -> sum+=number+' '}

    10.downto(1){}//一样

    //

    store=''

    0.step(0.6,0.1){n->store+=n+' '}   //0.6为终止边界不包括,0.1为增幅

    assert store=='0 0.1 0.2 0.3 0.4 0.5'

     

     

    最新回复(0)