Reputation: 33
I need to turn a floating point number (0.02) into a percentage(2%). What is they syntax in ruby?
Upvotes: 2
Views: 4833
Reputation: 149
To convert a float to a percentage, multiply the float by 100. If you need to output it with the % sign, use string interpolation inside a string.
Example:
percentage_value = 0.02 * 100
puts "#{percentage_value}%"
2.0%
{edited}
Upvotes: 2