Standard library / math/big
big.Rat.MarshalText()
Encode a rational using its textual fraction representation; check errors. Expected stdout: '-2/3\n'.
Formal Syntax & Structure
go syntaxgo
func (x *Rat) 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.NewRat(-2, 3).MarshalText() check(e) fmt.Println(string(b))}