https://tc39.es/ecma262/2024/multipage/ecmascript-data-types-and-values.html#sec-numeric-types-number-tostring
()
| 15 | |
| 16 | // https://tc39.es/ecma262/2024/multipage/ecmascript-data-types-and-values.html#sec-numeric-types-number-tostring |
| 17 | func (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 |
| 41 | func FromString(s string) Number { |