fix handling of default precision in formatBiggestFloat for the js backend (#7928)
This commit is contained in:
parent
07ff9940f4
commit
91765e583d
1 changed files with 7 additions and 0 deletions
|
|
@ -1854,6 +1854,10 @@ proc formatBiggestFloat*(f: BiggestFloat, format: FloatFormatMode = ffDefault,
|
||||||
##
|
##
|
||||||
## If ``precision == -1``, it tries to format it nicely.
|
## If ``precision == -1``, it tries to format it nicely.
|
||||||
when defined(js):
|
when defined(js):
|
||||||
|
var precision = precision
|
||||||
|
if precision == -1:
|
||||||
|
# use the same default precision as c_sprintf
|
||||||
|
precision = 6
|
||||||
var res: cstring
|
var res: cstring
|
||||||
case format
|
case format
|
||||||
of ffDefault:
|
of ffDefault:
|
||||||
|
|
@ -1863,6 +1867,9 @@ proc formatBiggestFloat*(f: BiggestFloat, format: FloatFormatMode = ffDefault,
|
||||||
of ffScientific:
|
of ffScientific:
|
||||||
{.emit: "`res` = `f`.toExponential(`precision`);".}
|
{.emit: "`res` = `f`.toExponential(`precision`);".}
|
||||||
result = $res
|
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:
|
for i in 0 ..< result.len:
|
||||||
# Depending on the locale either dot or comma is produced,
|
# Depending on the locale either dot or comma is produced,
|
||||||
# but nothing else is possible:
|
# but nothing else is possible:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue