Standard library / math/big

big.Rat.Scan()

Implement fmt.Scanner for rational values; supported float-style verbs and v are equivalent. This method writes to the receiver (use a separate destination to preserve inputs when needed). Expected stdout: '1 3/8\n'.

Formal Syntax & Structure

go syntaxgo
func (z *Rat) Scan(s fmt.ScanState, ch rune) error

Parameters & Attributes

NameTypeDescription
sfmt.ScanStateText input or formatting/scanning state, according to the signature.
chruneFormat verb supplied by fmt.

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)  n, e := fmt.Sscan("3/8", z)  check(e)  fmt.Println(n, z)}
Go Reference