Standard library / math/big

big.Rat.SetFloat64()

Represent the existing finite float64 exactly as a rational; nonfinite input returns nil. This does not recover a decimal literal's intended exact value. This method writes to the receiver (use a separate destination to preserve inputs when needed). Expected stdout: '3602879701896397/36028797018963968\n'.

Formal Syntax & Structure

go syntaxgo
func (z *Rat) SetFloat64(f float64) *Rat

Parameters & Attributes

NameTypeDescription
ffloat64Numeric operand supplied to this method.

Return Value

*Rat

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(new(big.Rat).SetFloat64(0.1))}
Go Reference