Skip to content

Instantly share code, notes, and snippets.

@kopos
Created February 11, 2021 04:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kopos/7454fc340c429cb6e38a6e822b87a9f3 to your computer and use it in GitHub Desktop.
Save kopos/7454fc340c429cb6e38a6e822b87a9f3 to your computer and use it in GitHub Desktop.
Clojure rounding
(bigdec 5)
(* (bigdec 5) 2)
(* 3 (bigdec 5))
(* (bigdec 5) 0.2)
(* (bigdec 5) (bigdec 6))
(+ (bigdec 5) (bigdec 6))
(.divide (bigdec 5) (bigdec 6) 2 java.math.RoundingMode/HALF_UP)
;; doesn't work
(.divide (bigdec 5) 3 2 java.math.RoundingMode/HALF_UP)
(with-precision 2 (/ 2M 3M))
; doesn't work
(with-precision 2 (bigdec 1.33333333))
(.setScale (bigdec 1.333333333) 2 java.math.RoundingMode/HALF_UP)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment