Skip to content

Instantly share code, notes, and snippets.

@akolybelnikov
Created November 1, 2018 20:32
Show Gist options
  • Save akolybelnikov/9b21d931da0cdc5d82d0b94b750bfaa4 to your computer and use it in GitHub Desktop.
Save akolybelnikov/9b21d931da0cdc5d82d0b94b750bfaa4 to your computer and use it in GitHub Desktop.
Truncate floating point numbers in Go
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