Standard library / math/big

big.Rat.SetString()

Parses a fraction or supported decimal/exponent form exactly; returns nil,false on failure. Expected stdout: '1/10 true\n'.

Formal Syntax & Structure

go syntaxgo
func (z *Rat) SetString(s string) (*Rat, bool)

Parameters & Attributes

NameTypeDescription
sstringInput text.

Return Value

(*Rat, bool)

Parses a fraction or supported decimal/exponent form exactly; returns nil,false on failure.

Working Example

Example Snippetgo
package main
import (  "fmt"  "math/big")
func main() {  v, ok := new(big.Rat).SetString("0.1")  fmt.Println(v, ok)}
Go Reference