icps

notes

四捨五入

1
2
3
4
5
6
7
8
9
10
11
#!/usr/bin/env ruby
# encoding: utf-8
def n425(num)
  test = num.to_s.match(/(\d*)\.(\d{1})/)
  test[2].to_i >= 5 ? test = test[1].to_i+1 : test = test[1].to_i
  num < 0 ? test*(-1) : test
end

def n425(num)
  num.to_s.to_f.round
end