This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-11-03
Channels
- # admin-announcements (7)
- # beginners (30)
- # boot (181)
- # cbus (1)
- # cider (55)
- # cljs-dev (8)
- # clojure (104)
- # clojure-dev (3)
- # clojure-japan (1)
- # clojure-russia (70)
- # clojurescript (139)
- # core-logic (4)
- # cursive (23)
- # datomic (25)
- # devcards (10)
- # events (11)
- # funcool (1)
- # hoplon (39)
- # jobs (10)
- # ldnclj (19)
- # lein-figwheel (21)
- # off-topic (4)
- # om (174)
- # onyx (46)
- # re-frame (25)
- # reagent (3)
- # yada (7)
DecimalFormat in java is probably what you want to use, if you want to relegate the parsing to something else
Sorry, NumberFormat
@roberto: This should work
(let [currencyParser (java.text.NumberFormat/getCurrencyInstance java.util.Locale/US)]
(.parse currencyParser "$10.00"))
;; => 10
I resorted to replace
😞
(defn str->bigdec
[v]
(-> (clojure.string/replace v #"\$" "")
(clojure.string/replace #"," "")
bigdec))
For future reference, you probably just needed to change the negative prefix / suffix
user> (def currencyParser (java.text.NumberFormat/getCurrencyInstance java.util.Locale/US))
;; => #'user/currencyParser
user> (.getNegativePrefix currencyParser)
;; => "($"
user> (.setNegativePrefix currencyParser "-$")
;; => nil
user> (.setNegativeSuffix currencyParser "")
;; => nil
user> (.parse currencyParser "-$10")
;; => -10
user>
ugh! Why didn’t they override the parse function so you can pass in the prefix? Hmm, I wonder if the negative prefix would ever be something other than -
????
sorry for sounding so whiney, working with obscure data formats (ofx) has me in a sour mood.
Can anyone tell me if it is bad practice to directly access fields on an object created from a type?
What's the deal with code-reloading in Pedestal? I've followed the instructions in https://github.com/pedestal/pedestal/issues/290 Which works, but as soon as the view is in a different namespace from the routes, you've gotta reload both the views and the routes... Which is pretty annoying.
I dont have any experience with pedestal but could it be wrapped in ring's reload middleware? https://github.com/ring-clojure/ring/blob/master/ring-devel/src/ring/middleware/reload.clj
I think if you use lein-ring
lein ring server-headless
it wraps stuff for you.
https://github.com/weavejester/lein-ring/blob/17cd6cb3b0cce6b842da1623bb2023326906cbb3/src/leiningen/ring/server.clj