Rails: How to print a decimal as a percent?
问题 Is there a way to print a decimal as a percentage, so only the two digits after the period? My decimals will always be between 1 and 0, so I suppose it would work to call number.round(2) starting with the third character, but I can't find the syntax for that anywhere. To clarify, I want the number to be stored as a full decimal , but printed as a percentage . 回答1: You are probably going to want to use the number_to_percentage method. From the documentation, here are some examples of how to