How to get the first digit after the decimal point of a float number in Go

1 Answer

0 votes
package main

import (
    "fmt"
    "math"
)

func main() {
    f := 983.6571

    n := int(math.Floor(math.Abs(f) * 10)) % 10

    fmt.Println(n)
}



/*
run:

6

*/

 



answered Oct 30, 2024 by avibootz
...