ruby 数值取整问题
怪我咯
怪我咯 2017-04-24 09:09:25
0
2
767

我想对一个数值做以下类似的取整,如:

4001 取整到 10000
5010 取整到 10000
100001 取整到 20000

依次类推,请问有什么好的方法吗?

补充:我想将一个不是很规则的值取一个比它大的规则值。

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(2)
伊谢尔伦
ruby    def ten_thouusand_ceil(n)
        (n.fp 10000).ceil * 10000
    end

2.1.5 :015 > ten_thouusand_ceil 4001 => 10000
2.1.5 :016 > ten_thouusand_ceil 5010 => 10000
2.1.5 :017 > ten_thouusand_ceil 10001 => 20000

迷茫

It can be like this

def get_num(n)
  while j ||= 0
    return 10**j if n <= 10**j
    j = j + 1
  end
end
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!