Standard library / math/big

big.Int.MarshalText()

Encode a signed integer as decimal text via encoding.TextMarshaler. Expected stdout: '-42\n'.

Formal Syntax & Structure

go syntaxgo
func (x *Int) MarshalText() (text []byte, err error)

Return Value

(text []byte, err error)

Returns the result described above; see the example for the observed behavior.

Working Example

Example Snippetgo
package main
import (  "fmt"  "math/big")
func check(err error) {  if err != nil {    panic(err)  }}func main() {  b, e := big.NewInt(-42).MarshalText()  check(e)  fmt.Println(string(b))}
Go Reference