purescript-contrib / purescript-formatters

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

Rounding up to next 1's digit bug #55

Closed ntwilson closed 4 years ago

ntwilson commented 4 years ago

from the REPL:

> import Data.Formatter.Number
> numberFormatOptions = Formatter { abbreviations: false, after: 1, before: 0, comma: true, sign: false }                
> format numberFormatOptions 1.99
"1.10"

However, if there are no trailing digits, it seems to work

> import Data.Formatter.Number
> numberFormatOptions = Formatter { abbreviations: false, after: 0, before: 0, comma: true, sign: false }
> format numberFormatOptions 1.9  
"1"

though it's an interesting behavior in that it floors instead of rounds, when other digits do round:

> import Data.Formatter.Number
> numberFormatOptions = Formatter { abbreviations: false, after: 1, before: 0, comma: true, sign: false }
> format numberFormatOptions 1.39
"1.4"
thomashoneyman commented 4 years ago

Hm -- that's not good. Seems that there's something wrong in the Numbers formatter: https://github.com/purescript-contrib/purescript-formatters/blob/master/src/Data/Formatter/Number.purs

and there's no test for various rounding lengths in the Numbers tests: https://github.com/purescript-contrib/purescript-formatters/blob/master/test/src/Number.purs

I agree that the most sensible thing to do is to round the number, not floor it, and that this behavior is unexpected. I don't have time at the moment to fix this but I've added the 'help wanted' label for anyone who is able to take a quick stab at it.

ntwilson commented 4 years ago

I took a stab at it, but as I mentioned in my PR, this is my first PR to any of the PureScript core libs, so a solid review would really help!