Last active
March 7, 2018 04:07
-
-
Save thescubageek/85236625fbf98cf0864d05a659ded9f4 to your computer and use it in GitHub Desktop.
steem_percentage.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SteemPercentage | |
extend ActiveSupport::Concern | |
STEEM_MAX_PERCENT = 10000.0 | |
# converts to [0.0-1.0] => percent_decimal(8000) == 0.8 | |
def percent_decimal(num) | |
num.to_f / STEEM_MAX_PERCENT | |
end | |
# converts to [0.0-100.0] => percent(8000) == 80.0 | |
def percent(num) | |
percent_decimal(num) * 100.0 | |
end | |
# converts to % format => percent_str(8000) == '80.0%' | |
def percent_str(num, precision=1) | |
"#{number_with_precision(percent(num), precision)}%" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment