I'm new to Golang. I wanted to separate a floating point number into whole and decimal parts. After some research I implemented it but there is a problem in my code. I'm using 5.8 as the input but the result is 5 and 0.79999.
package main
import(
"fmt"
"math"
)
func Round2(val float64) {
intpart, div := math.Modf(val)
fmt.Println(div)
fmt.Println(intpart)
}
func main() {
fmt.Println("Hello, playground")
Round2(5.8)
}
I have tried this, I'm getting an output of:
0.7999999999999998
5
If there is any other way to do this please let me know. I have inserted the go playground with my code in it.