1

I have the following float: 2.554 and I need to format as percentage using ruby/rails.

How to round down that float ? I tried to use number_to_percentage but the value is displayed as 2.6 (round up)

1 Answers1

3

You cant use the round method specifying the number of digits to round. Sample

 2.554.round(2)
=> 2.55

With the next variant you can force to round down if the third digit after comma is less than 5

 2.555.round(2, half: :down)
=> 2.55
aconsuegra
  • 154
  • 1
  • 5