Standard library / math/big

big.Rat.Float64()

Return nearest float64 and exactness flag. Preserve rational form if exact fractions matter. Expected stdout: '0.125 true\n'.

Formal Syntax & Structure

go syntaxgo
func (x *Rat) Float64() (f float64, exact bool)

Return Value

(f float64, 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, 8).Float64()  fmt.Println(v, ok)}
Go Reference