Module: Pyk::NumberHelpers
- Defined in:
- lib/pyk/number_helpers.rb
Instance Method Summary collapse
- #color_amount(d) ⇒ Object
- #n2h(d) ⇒ Object
- #remove_decimal(str) ⇒ Object
- #stock_market(d) ⇒ Object
- #two_decimal_points(ff) ⇒ Object
Instance Method Details
#color_amount(d) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/pyk/number_helpers.rb', line 33 def color_amount(d) if d < 0 "<span class='red'>(#{number_to_currency(d, unit: '')})</span>".html_safe else number_to_currency(d, unit: '') end end |
#n2h(d) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/pyk/number_helpers.rb', line 15 def n2h(d) begin return number_to_human(d, significant: false, precision: 1) rescue return d end end |
#remove_decimal(str) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/pyk/number_helpers.rb', line 7 def remove_decimal(str) str = str.to_s if str.index(".").present? str = str[0..(str.index(".") - 1)] end str end |
#stock_market(d) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/pyk/number_helpers.rb', line 23 def stock_market(d) if d < 0 return "<span style='color: red;'><i class='icon-arrow-down'></i></span> #{d}%".html_safe elsif d > 0 return "<span style='color: green;'><i class='icon-arrow-up'></i></span> #{d}%".html_safe else return d end end |
#two_decimal_points(ff) ⇒ Object
3 4 5 |
# File 'lib/pyk/number_helpers.rb', line 3 def two_decimal_points(ff) sprintf("%0.02f", ff) end |