Standard library / math/big

big.Rat.String()

Return fraction notation a/b even when the denominator is one. Expected stdout: '2/1\n'.

Formal Syntax & Structure

go syntaxgo
func (x *Rat) String() string

Return Value

string

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

Working Example

Example Snippetgo
package main
import (  "fmt"  "math/big")
func main() {  fmt.Println(big.NewRat(6, 3).String())}
Go Reference