Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coercion for Decimal doesn't work as expected #15

Closed
LukasRychtecky opened this issue Dec 14, 2018 · 2 comments
Closed

Coercion for Decimal doesn't work as expected #15

LukasRychtecky opened this issue Dec 14, 2018 · 2 comments

Comments

@LukasRychtecky
Copy link
Contributor

Hi,
thank you for this library.

When I get a number from e.g. Ring request I'd like to coerce it to Big Decimal.

(s/def ::amount (s/and decimal? pos?))
(sc/coerce ::amount "") ;; throws java.lang.ArrayIndexOutOfBoundsException
;; but I expect to get "", because the value is not possible to coerce

(sc/coerce ::amount 1) ;; it returns 1
;; but I expect to get 1M, because the value is Long 

So I suggest to:

  1. parse-decimal function should not care if x is string or not.
  2. parse-decimal should be wrapped in try-catch.

What do you think about it?

@wilkerlucio
Copy link
Owner

hello @LukasRychtecky :)

I think it makes sense, can you like to send a PR with the described changes?

@LukasRychtecky
Copy link
Contributor Author

@wilkerlucio Fine, I will create a PR ;)

wilkerlucio added a commit that referenced this issue Dec 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants