How to get the fraction and exponent of a real number in Go

1 Answer

0 votes
package main

import (
    "fmt"
    "math"
)

func main() {
    d := 3.14
    
    fraction, exponent := math.Frexp(d)
    
    fmt.Printf("fraction = %.3f exponent = %d\n", fraction, exponent)
}



/*
run:

fraction = 0.785 exponent = 2

*/

 



answered Jun 30, 2025 by avibootz
...