floating point numbers with first 2 decimals (without rounding)

def float_of_2_decimal(float_n) num = float_n.to_s.split('.') num[1] = num[1][0..1] num.join(".").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.