Created
October 10, 2023 08:13
-
-
Save Oxygenesis/6c9e9bdf0002a9b1c13e1ebcaf11fcc6 to your computer and use it in GitHub Desktop.
Golang Float Conversion Lost Precission for Data Over 10 Mio (from float64 to float32)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
func main() { | |
valueFloat64 := float64(12391240000) // example float64 value | |
valueInt64 := int64(valueFloat64) | |
valueFloat32 := float32(valueFloat64) | |
valueNewFloat64 := float64(valueFloat32) | |
fmt.Printf("%.0f\n", valueFloat64) //12391240000 | |
fmt.Printf("%.0f\n", valueFloat32) //12391239680 | |
fmt.Printf("%.0f\n", valueNewFloat64) //12391239680 | |
fmt.Printf("%d\n", valueInt64) //12391240000 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment