parent
e60c20bc10
commit
e1d2b9b1c1
|
@ -64,10 +64,10 @@
|
|||
Example usage:
|
||||
(convert-to-whole-number 12345 2) ; => 123.45"
|
||||
[amount decimals]
|
||||
(-> amount
|
||||
(/ (Math/pow 10 decimals))
|
||||
(.toFixed decimals)
|
||||
remove-trailing-zeroes))
|
||||
(when-let [[amount-bn divisor-bn] (money/->bignumbers amount (money/from-decimal decimals))]
|
||||
(-> (money/div amount-bn divisor-bn)
|
||||
(money/to-fixed decimals)
|
||||
remove-trailing-zeroes)))
|
||||
|
||||
(defn hex->whole
|
||||
[num decimals]
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
(ns utils.number-test
|
||||
(:require
|
||||
[cljs.test :refer [deftest is testing]]
|
||||
[utils.money :as money]
|
||||
[utils.number]))
|
||||
|
||||
(deftest convert-to-whole-number-test
|
||||
|
@ -21,7 +22,11 @@
|
|||
|
||||
(testing "handles zero amount"
|
||||
(is (= "0" (utils.number/convert-to-whole-number 0 2)))
|
||||
(is (= "0" (utils.number/convert-to-whole-number 0 0)))))
|
||||
(is (= "0" (utils.number/convert-to-whole-number 0 0))))
|
||||
|
||||
(testing "handles BigNumber amounts with 18 decimals"
|
||||
(let [amount (money/bignumber "3141969777175276657")]
|
||||
(is (= "3.141969777175276657" (utils.number/convert-to-whole-number amount 18))))))
|
||||
|
||||
(deftest parse-int-test
|
||||
(testing "defaults to zero"
|
||||
|
|
Loading…
Reference in New Issue