Module: Hirb::Helpers::Table::Filters

Defined in:
lib/stockfolio/formatters.rb

Instance Method Summary collapse

Instance Method Details

#to_dollars(amount) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/stockfolio/formatters.rb', line 4

def to_dollars(amount)
    if amount
        amount = amount.to_f
        if amount < 0
            sprintf('($%0.2f)',0-amount).gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,")
        else
            sprintf('$%0.2f',amount).gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,")
        end
    end
end

#to_percent(value) ⇒ Object



15
16
17
18
19
# File 'lib/stockfolio/formatters.rb', line 15

def to_percent(value)
    if value
        "#{(100.0 * value).round(1)}%"
    end
end