lamrin
lamrin

Reputation: 21

Ruby on Rails - Rounding ones, tens and hundred digit places

I want to round of the ones and tens digit positon for the value..

if it is 1999, it should display as 1900

and if it is 19999 it should display as 19000

code goes like this

{overall_cost.to_money.format(:no_cents)}

Upvotes: 1

Views: 1170

Answers (2)

Wayne Conrad
Wayne Conrad

Reputation: 107969

You can round like this:

(n.to_i / 100) * 100

However, you are asking for a monkey patch so that :nocents is a valid argument to... money, I guess. I poked around the rails source and didn't see where the monkey patch should go.

Upvotes: 6

Veger
Veger

Reputation: 37906

You could use something like this:

def myround(value)
  return value if value < 100
  temp = value.to_s
  temp[0..1] + "0" * (temp.lenth - 2)
end

Upvotes: 0

Related Questions