format prices with 2 decimal places always

This commit is contained in:
Gered 2016-07-10 17:15:53 -04:00
parent ac93a58829
commit f8d858e821
3 changed files with 9 additions and 8 deletions

View file

@ -7,7 +7,8 @@
[webtools.reagent.components :refer [raw-html]] [webtools.reagent.components :refer [raw-html]]
[mtgcoll.common :refer [max-search-results]] [mtgcoll.common :refer [max-search-results]]
[mtgcoll.client.components.utils :refer [set-short-label symboled-markup th-sortable]] [mtgcoll.client.components.utils :refer [set-short-label symboled-markup th-sortable]]
[mtgcoll.client.components.inventory :refer [inventory]])) [mtgcoll.client.components.inventory :refer [inventory]]
[mtgcoll.client.utils :refer [format-currency]]))
(defn card-image (defn card-image
[card-id & {:keys [width height]}] [card-id & {:keys [width height]}]
@ -86,8 +87,8 @@
(if (or power toughness) (if (or power toughness)
(str " (" power "/" toughness ")")))] (str " (" power "/" toughness ")")))]
[:td rarity] [:td rarity]
[:td paper_price] [:td (format-currency paper_price true)]
[:td online_price] [:td (format-currency online_price true)]
[:td [inventory id [:td [inventory id
{:num-owned owned_count {:num-owned owned_count
:button-size "xsmall" :button-size "xsmall"

View file

@ -9,7 +9,7 @@
[mtgcoll.client.components.cards :refer [card-image card-link]] [mtgcoll.client.components.cards :refer [card-image card-link]]
[mtgcoll.client.components.utils :refer [symbol-image set-heading set-label symboled-markup]] [mtgcoll.client.components.utils :refer [symbol-image set-heading set-label symboled-markup]]
[mtgcoll.client.components.inventory :refer [inventory]] [mtgcoll.client.components.inventory :refer [inventory]]
[mtgcoll.client.utils :refer [format-date format-datetime]])) [mtgcoll.client.utils :refer [format-date format-datetime format-currency]]))
(defn detail (defn detail
[& components] [& components]
@ -178,8 +178,8 @@
^{:key idx} ^{:key idx}
[:tr [:tr
[:td source] [:td source]
[:td paper-price] [:td (format-currency paper-price true)]
[:td online-price] [:td (format-currency online-price true)]
[:td (format-datetime last-updated)]]))))]]]) [:td (format-datetime last-updated)]]))))]]])
(if (and (seq @printings) (if (and (seq @printings)
(> (count @printings) 1)) (> (count @printings) 1))

View file

@ -60,6 +60,6 @@
(string/replace (str n) #"\B(?=(\d{3})+(?!\d))" ","))) (string/replace (str n) #"\B(?=(\d{3})+(?!\d))" ",")))
(defn format-currency (defn format-currency
[n] [n & [number-only?]]
(if n (if n
(str "$" (pprint/cl-format nil "~,2f" n)))) (str (if-not number-only? "$") (pprint/cl-format nil "~,2f" n))))