Created
November 1, 2018 20:32
-
-
Save akolybelnikov/9b21d931da0cdc5d82d0b94b750bfaa4 to your computer and use it in GitHub Desktop.
Truncate floating point numbers in Go
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" | |
"log" | |
"math" | |
) | |
func main() { | |
var userNumber float64 | |
fmt.Printf("Type in a floating point number:\n") | |
_, err := fmt.Scan(&userNumber) | |
if err != nil { | |
fmt.Printf("%s\n", "An error has occured:") | |
log.Fatal(err) | |
} | |
fmt.Printf("Truncated: %v\n", math.Trunc(userNumber)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment