floating point numbers with first 2 decimals (without rounding)

def float_of_2_decimal(float_n) float_n.round(3).to_s[0..3].to_f end
With `5.666666666666666666666` it will return `5.66` instead of rounded 5.67. I needed these kinds of numbers, without rounding.

3 Responses

Though It will fail on numbers with large integer part
@Caroline Artz

Write a comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.