purescript-contrib / purescript-formatters

Formatting and printing for numeric and date/time/interval values
Apache License 2.0
41 stars 30 forks source link

2 digits after decimal, less than 0.10, is improperly formatted #41

Closed paulbjarne closed 6 years ago

paulbjarne commented 6 years ago

I am using purescript-formatters to display USD formatted numbers. I am running into a subtle bug where numbers with decimal between 0.00 and 0.10 (i.e. $1.01 or $1.09) does not get formatted properly. An example of this bug is below -

formattedNumber :: String
formattedNumber =
  let 
    fmtter = Formatter
      { comma: false
      , before: 0
      , after: 2
      , abbreviations: false
      , sign: false
      }
  in 
    format fmtter 1.09

-- formattedNumber == "1.9"

Here is a link to a branch with a failing test demonstrating this.

I may have a PR that can fix this upcoming.

safareli commented 6 years ago

I may have a PR that can fix this upcoming.

Looking forward

There are also ~#30~ #16, all of which are related to the issue.

garyb commented 6 years ago

30 is different as that relates to the date formatter :)

safareli commented 6 years ago

Correct, I saw digit and thought it was also related to numbers :d

paulbjarne commented 6 years ago

42 does the trick for us.

We made the change on a much older version (v1.0.0 :grimacing:), but it rebased cleanly against current master. I also added the test that I linked to above (failing before these changes, but now passing).

paulbjarne commented 6 years ago

This should be fixed with #42 getting merged, closing.