Standard library / math/big

big.Rat.Float32()

Return nearest float32 and whether conversion is exact; overflow may return infinity. Expected stdout: '0.333333 false\n'.

Formal Syntax & Structure

go syntaxgo
func (x *Rat) Float32() (f float32, exact bool)

Return Value

(f float32, exact bool)

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

Working Example

Example Snippetgo
package main
import (  "fmt"  "math/big")
func main() {  v, ok := big.NewRat(1, 3).Float32()  fmt.Printf("%.6f %t\n", v, ok)}
Go Reference