Standard library / math/big

big.Rat.UnmarshalText()

Parse a textual rational into the receiver, returning an error on invalid input. This method writes to the receiver (use a separate destination to preserve inputs when needed). Expected stdout: '1/8\n'.

Formal Syntax & Structure

go syntaxgo
func (z *Rat) UnmarshalText(text []byte) error

Parameters & Attributes

NameTypeDescription
text[]byteEncoded textual input.

Return Value

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() {  z := new(big.Rat)  check(z.UnmarshalText([]byte("0.125")))  fmt.Println(z)}
Go Reference