jsnumber

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package jsnumber implements ECMAScript numeric conversion and serialization for values that arrive as JSON.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromJSON

func FromJSON(raw []byte) float64

FromJSON returns ToNumber of the value JSON.parse produces for raw. A nil or empty raw is undefined, which converts to NaN.

func JSON

func JSON(value float64) json.RawMessage

JSON returns JSON.stringify(value): non-finite numbers serialize as null and -0 as 0.

func Parse

func Parse(text string) float64

Parse implements ECMAScript StringToNumber.

func ParseInt

func ParseInt(text string) float64

ParseInt is Number.parseInt(text, 10): after JavaScript whitespace and an optional sign it reads the longest run of ASCII digits, and is NaN when none follows.

func Round

func Round(value float64) float64

Round is Math.round: the integral value nearest value, with halves toward +Infinity. A value in [-0.5, 0) rounds to -0, one in (0, 0.5) to +0, and NaN, infinities and zeros return unchanged. Unlike math.Floor(value+0.5), it does not round 0.49999999999999994 up or move an odd integer above 2^52, where the addition itself rounds.

func String

func String(value float64) string

String implements Number::toString for base 10.

func StringFromJSON

func StringFromJSON(raw []byte) string

StringFromJSON returns ToString (String(value)) of the value JSON.parse produces for raw. A nil or empty raw is undefined.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL