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

unformatNumber seems to be broken #16

Open
commandodev opened this issue Mar 30, 2017 · 3 comments
Open

unformatNumber seems to be broken #16

commandodev opened this issue Mar 30, 2017 · 3 comments
Labels
type: bug Something that should function correctly isn't.

Comments

@commandodev
Copy link

> import Data.Formatter.Number (unformatNumber)
> unformatNumber ("00.00") "5.0"
(Left "Error: too few digits before dot")

> unformatNumber ("00.00") "50.0"
(Left "Error: too few digits after dot")

> unformatNumber ("00.00") "50.00"
(Right 50.0)

> unformatNumber ("00.00") "50.0234252"
(Right 2392.52)

> unformatNumber ("0.00") "50.0234252"
(Right 2392.52)

> unformatNumber ("0.0") "50.0234252"
(Right 23475.2)

I'm not sure if the first two are expected or not, but the last two seem clearly wrong.

@safareli safareli added the type: bug Something that should function correctly isn't. label Oct 4, 2017
@safareli
Copy link
Contributor

safareli commented Oct 4, 2017

> unformatNumber "0.0" "1507142848002.0"
(Right -390672894.0)

from #38 by @Houndolon

@safareli
Copy link
Contributor

safareli commented Oct 4, 2017

I think issue is that we should check for equality here
https://github.com/slamdata/purescript-formatters/blob/master/src/Data/Formatter/Number.purs#L184-L193

  before ←
    if Arr.length beforeDigits == f.before
    then P.fail $ "Error: need to have" <> show f.after <> " digits before dot"
    else pure $ Int.toNumber $ foldDigits beforeDigits

  afterDigits ← some parseDigit
  after ←
    if Arr.length afterDigits == f.after
    then P.fail $ "Error: need to have" <> show f.after <> " digits after dot"
    else pure $ Int.toNumber $ foldDigits afterDigits

@safareli
Copy link
Contributor

safareli commented Oct 4, 2017

@cryogenian is this what you have suggested before as solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something that should function correctly isn't.
Development

No branches or pull requests

2 participants