Aravind
Aravind

Reputation: 1401

Round to 0.5 or 1 in ruby

Where x is any integer, I have a value about x.1..x.4. I want to round it to x.5, and if it is above x.5, say x.7 or x.8, then it should round to (x+1).0. How is that possible? Is there a function in ruby?

Upvotes: 3

Views: 1526

Answers (1)

mrd abd
mrd abd

Reputation: 858

use (v*2).ceil.to_f / 2 where v is your variable.

Upvotes: 10

Related Questions