mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-27 17:53:58 +00:00
$(a: float) now works consistently in nim js, avoiding printing floats as ints (#14134)
* fix https://github.com/timotheecour/Nim/issues/133; $(a: float) works in nim js like in other backends * fix tests * fix test for windows that prints 1.1e17 differently than other OS
This commit is contained in:
@@ -476,6 +476,21 @@ proc negInt(a: int): int {.compilerproc.} =
|
||||
proc negInt64(a: int64): int64 {.compilerproc.} =
|
||||
result = a*(-1)
|
||||
|
||||
proc nimFloatToString(a: float): cstring {.compilerproc.} =
|
||||
## ensures the result doesn't print like an integer, ie return 2.0, not 2
|
||||
asm """
|
||||
function nimOnlyDigitsOrMinus(n) {
|
||||
return n.toString().match(/^-?\d+$/);
|
||||
}
|
||||
if (Number.isSafeInteger(`a`)) `result` = `a`+".0"
|
||||
else {
|
||||
`result` = `a`+""
|
||||
if(nimOnlyDigitsOrMinus(`result`)){
|
||||
`result` = `a`+".0"
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
proc absInt(a: int): int {.compilerproc.} =
|
||||
result = if a < 0: a*(-1) else: a
|
||||
|
||||
|
||||
Reference in New Issue
Block a user