Enable number_to_percentage to keep the number's precision by allowing :precision option value to be nil #12067

merged 1 commit into from Feb 6, 2015


None yet

2 participants

jackxxu commented Aug 29, 2013

When converting numbers to percentage using number_to_percentage helper method, it is sometimes necessary to keep the numbers’ precision as is, without having to set an arbitrary precision value.

for example, we have an array of numbers, and I would like to keep their precision so that

numbers = [1000, 0.12, 43.1]
numbers.map {|x| number_to_percentage(x, precision: nil)}  # =>  ['1000%', '0.12%', '43.1%']
@jackxxu jackxxu Enable number_to_percentage to keep the number's precision by allowin…
…g :precision to be nil

number_helper.number_to_percentage(1000, precision: nil) # => "1000%"
@rafaelfranca rafaelfranca merged commit 24a7e60 into rails:master Feb 6, 2015

1 check passed

default The Travis CI build passed
@rafaelfranca rafaelfranca added a commit that referenced this pull request Feb 6, 2015
@rafaelfranca rafaelfranca Merge branch 'rm-ntp'
Merge #12067 rebasing and improving the code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment