purescript-contrib / purescript-formatters

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

Numbers >10 digits are formatted wrongly #63

Closed MuratOzsoyler closed 3 years ago

MuratOzsoyler commented 3 years ago

Describe the bug If number is greater than 10 digits formatNumber always returns 02147483647.2147483647 or alike.

To Reproduce

> formatNumber "000000000000.0" 1234567899.0 
(Right "001234567899.0")

but

> formatNumber "000000000000.0" 12345678901.0
(Right "02147483647.2147483647")

Expected behavior Numbers up to 12345678901234564.0 can exactly be shown. So formatNumber should format them. If for whatever reason it could not format reasonably then Left should be returned.

MuratOzsoyler commented 3 years ago

This is a very interesting situation. I forked the repo and compiled. Tests are successfully run. And result in the REPL is

> formatNumber "0.0" 1234567890123459.0
(Right "1234567890123459.0")

I thought the problem might be related to the compiler version (head can not be compiled older than 0.14 purescript) so checked out commit 3411dbc16efcf6fe9ea0760434dc153f5cc99c58. Compiled with 0.13.8 and tested. Result:

> formatNumber "0.0" 1234567890123459.0
(Right "1234567890123459.0")

I started to blame myself for the false alarm. Just for curiosity I tested one more time in my original project (ps 0.13.8, formatters 4.0.1). The result is this time is:

> formatNumber "0.0" 1234567890123459.0
(Right "2147483647.2147483647")

Both repls are open on my monitor now and one succeeds and one fails!

JuanFML commented 3 years ago

Hi I am new here could I resolve this as my firs issue?

thomashoneyman commented 3 years ago

I do see this on Try PureScript:

module Main where

import Prelude
import Effect (Effect)
import Effect.Console (logShow)
import TryPureScript (render, withConsole)
import Data.Formatter.Number (formatNumber)

main :: Effect Unit
main = render =<< withConsole do
  logShow $ formatNumber "0.0" 1234567890123459.0

producing (Right "2147483647.2147483647"). I think there's definitely something up here, though I haven't yet looked into this issue.

thomashoneyman commented 3 years ago

@JuanFML Please feel free! No one else is working on this at the moment (as far as I know).

JuanFML commented 3 years ago

Cool! I will try to solve it, if I have any issue I'll let you know

JuanFML commented 3 years ago

Hi! I looked into the problem through the weekend and I think on the actual repo the problem is generated in a different way than in TryPurescript, I wasn't able to fix it, but I think maybe it has to do with the operations that occur in the formatter. I am new to PureScript, so If you want to solve it go ahead,

ntwilson commented 3 years ago

This is a little late, but I believe that this was fixed between v4.0.1 and v5.0.0.
See this discussion https://github.com/purescript-contrib/purescript-formatters/pull/56#discussion_r471893147 from a PR that got merged as part of 5.0.0.
I think this issue can be closed?

thomashoneyman commented 3 years ago

Thanks @ntwilson!