You can use the to_f function with round to change the string to float with exact decimal to_f . For example, I am printing text about the frequency value in a .pdf file. Raw data in string .
text "#{(@qsos.frequency.to_f).round(3)} MHz"
As a result, original text such as 7.13500 will be converted to 7.135 . If we try to round value directly, it will return an error, as in string . So, we need to first convert it to a floating point number before we define the decimal places.
source share