diff options
author | skilchen <skilchen@users.noreply.github.com> | 2018-06-02 04:24:32 +0200 |
---|---|---|
committer | Varriount <Varriount@users.noreply.github.com> | 2018-06-01 22:24:32 -0400 |
commit | 91765e583da91b8288e18e74d4196713dc2ede18 (patch) | |
tree | 08a29031bf203be6ab1707e629eec5a05cce7368 /lib | |
parent | 07ff9940f4a990b57cfaa3ad274c7bcff46356ff (diff) | |
download | Nim-91765e583da91b8288e18e74d4196713dc2ede18.tar.gz |
fix handling of default precision in formatBiggestFloat for the js backend (#7928)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/strutils.nim | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim index ee3072c85..a4fd20fdb 100644 --- a/lib/pure/strutils.nim +++ b/lib/pure/strutils.nim @@ -1854,6 +1854,10 @@ proc formatBiggestFloat*(f: BiggestFloat, format: FloatFormatMode = ffDefault, ## ## If ``precision == -1``, it tries to format it nicely. when defined(js): + var precision = precision + if precision == -1: + # use the same default precision as c_sprintf + precision = 6 var res: cstring case format of ffDefault: @@ -1863,6 +1867,9 @@ proc formatBiggestFloat*(f: BiggestFloat, format: FloatFormatMode = ffDefault, of ffScientific: {.emit: "`res` = `f`.toExponential(`precision`);".} result = $res + if 1.0 / f == -Inf: + # JavaScript removes the "-" from negative Zero, add it back here + result = "-" & $res for i in 0 ..< result.len: # Depending on the locale either dot or comma is produced, # but nothing else is possible: |