MCPcopy Create free account
hub / github.com/microsoft/typescript-go / String

Method String

internal/jsnum/string.go:17–38  ·  view source on GitHub ↗

https://tc39.es/ecma262/2024/multipage/ecmascript-data-types-and-values.html#sec-numeric-types-number-tostring

()

Source from the content-addressed store, hash-verified

15
16// https://tc39.es/ecma262/2024/multipage/ecmascript-data-types-and-values.html#sec-numeric-types-number-tostring
17func (n Number) String() string {
18 switch {
19 case n.IsNaN():
20 return "NaN"
21 case n.IsInf():
22 if n < 0 {
23 return "-Infinity"
24 }
25 return "Infinity"
26 }
27
28 // Fast path: for safe integers, directly convert to string.
29 if MinSafeInteger <= n && n <= MaxSafeInteger {
30 if i := int64(n); float64(i) == float64(n) {
31 return strconv.FormatInt(i, 10)
32 }
33 }
34
35 // Otherwise, the Go json package handles this correctly.
36 b, _ := json.Marshal(float64(n))
37 return string(b)
38}
39
40// https://tc39.es/ecma262/2024/multipage/abstract-operations.html#sec-stringtonumber
41func FromString(s string) Number {

Callers

nothing calls this directly

Calls 4

IsNaNMethod · 0.95
IsInfMethod · 0.95
MarshalFunction · 0.92
stringEnum · 0.50

Tested by

no test coverage detected