document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. (defn as-currency
  2.   "Money amounts are transmitted as \\"$2.44\\".
  3.  Parse this and return a numeric type."
  4.   [currency-amount]
  5.   ;; strip off the leading "$"
  6.   (let [stripped (subs currency-amount 1)
  7.         _ (println "stripped" currency-amount "->" stripped)
  8.         decimal (bigdec stripped)
  9.         _ (println "bigdec" stripped "->" decimal)]
  10.     decimal))
  11.  
  12. ;;;; Re-evaluating the sample calculation gives us this:
  13.  
  14. ;; stripped $1200.20 -> 1200.20
  15. ;; bigdec 1200.20 -> 1200.20M
  16. ;; stripped $0.03 -> 0.03
  17. ;; bigdec 0.03 -> 0.03M
  18. ;; stripped $120.00 -> 120.00
  19. ;; bigdec 120.00 -> 120.00M
  20. ;; stripped $5.99 -> 5.99
  21. ;; bigdec 5.99 -> 5.99M
  22. ;; stripped $20 -> 20
  23. ;; bigdec 20 -> 20M
  24. ;; stripped $12.33 -> 12.33
  25. ;; bigdec 12.33 -> 12.33M
  26. ;; stripped -$4.50 -> $4.50
  27. ;; NumberFormatException   java.math.BigDecimal.<init> (BigDecimal.java:494)
');