better formatting of money

This commit is contained in:
Andrew Tomaka 2015-04-23 15:09:39 -04:00
parent a01cd54e6a
commit ea5c8acc68
2 changed files with 6 additions and 5 deletions

5
app.rb
View file

@ -29,11 +29,12 @@ end
def readable_number(value) def readable_number(value)
numbers.each do |number, symbol| numbers.each do |number, symbol|
if value.to_f / number.to_f > 1 if value.to_f / number.to_f > 1
return (value.to_f / number.to_f).round(2).to_s + '<strong>' + symbol + '</strong>' return sprintf('%.2f', value.to_f / number.to_f) + '<strong>' + symbol + '</strong>'
end end
end end
return value value = 0.0 unless value
return sprintf('%.2f', value) + "_"
end end
def numbers def numbers

View file

@ -1,6 +1,6 @@
<h2>Index</h2> <h2>Index</h2>
<table class="table table-striped"> <table class="table table-striped table-hover table-bordered table-condensed">
<thead> <thead>
<tr> <tr>
<td>Attacker</td> <td>Attacker</td>
@ -15,8 +15,8 @@
<tr> <tr>
<td><%= raid.attacker %></td> <td><%= raid.attacker %></td>
<td><%= raid.defender %></td> <td><%= raid.defender %></td>
<td><%= readable_number(raid.soldiers) %></td> <td class="text-right"><%= readable_number(raid.soldiers) %></td>
<td><%= readable_number(raid.money) %></td> <td class="text-right"><%= readable_number(raid.money) %></td>
<td><%= raid.created_at %></td> <td><%= raid.created_at %></td>
</tr> </tr>
<% end %> <% end %>