From ea5c8acc684244f427230b6681721dc595cfb33e Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Thu, 23 Apr 2015 15:09:39 -0400 Subject: [PATCH] better formatting of money --- app.rb | 5 +++-- views/index.erb | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app.rb b/app.rb index 7a120f3..a3f3e08 100644 --- a/app.rb +++ b/app.rb @@ -29,11 +29,12 @@ end def readable_number(value) numbers.each do |number, symbol| if value.to_f / number.to_f > 1 - return (value.to_f / number.to_f).round(2).to_s + '' + symbol + '' + return sprintf('%.2f', value.to_f / number.to_f) + '' + symbol + '' end end - return value + value = 0.0 unless value + return sprintf('%.2f', value) + "_" end def numbers diff --git a/views/index.erb b/views/index.erb index 09222c6..7ea2b84 100644 --- a/views/index.erb +++ b/views/index.erb @@ -1,6 +1,6 @@

Index

- +
@@ -15,8 +15,8 @@ - - + + <% end %>
Attacker
<%= raid.attacker %> <%= raid.defender %><%= readable_number(raid.soldiers) %><%= readable_number(raid.money) %><%= readable_number(raid.soldiers) %><%= readable_number(raid.money) %> <%= raid.created_at %>