M
Manu Sankala
At school I was taught that five is always rounded up. Later on I've
been told that sometimes five is rounded to closest even number. Neither
of these seem to be the case with ruby:
irb(main):044:0> RUBY_VERSION
=> "1.8.7"
irb(main):045:0> (217.5).round
=> 218
irb(main):046:0> (218.5).round
=> 219
irb(main):047:0> (2.175*100).round
=> 217
irb(main):048:0> (2.185*100).round
=> 219
irb(main):049:0> sprintf('%.2f',2.175)
=> "2.17"
irb(main):050:0> (2.175*100.0).round/100.0
=> 2.17
Can someone please tell me how do I round 2.175 to 2.18, besides
((2.175*100).to_s+'9').to_f.round/100.0 ?
-
Manu S
been told that sometimes five is rounded to closest even number. Neither
of these seem to be the case with ruby:
irb(main):044:0> RUBY_VERSION
=> "1.8.7"
irb(main):045:0> (217.5).round
=> 218
irb(main):046:0> (218.5).round
=> 219
irb(main):047:0> (2.175*100).round
=> 217
irb(main):048:0> (2.185*100).round
=> 219
irb(main):049:0> sprintf('%.2f',2.175)
=> "2.17"
irb(main):050:0> (2.175*100.0).round/100.0
=> 2.17
Can someone please tell me how do I round 2.175 to 2.18, besides
((2.175*100).to_s+'9').to_f.round/100.0 ?
-
Manu S