From cacd1817ee4064051f913f3c4c31b66d1939f352 Mon Sep 17 00:00:00 2001 From: Khalil SLEIMI Date: Fri, 21 Jan 2022 11:18:10 +0100 Subject: [PATCH] Read float and print truncated --- hello.go | 2 +- trunc.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 trunc.go diff --git a/hello.go b/hello.go index a3dd973..68de9aa 100644 --- a/hello.go +++ b/hello.go @@ -2,6 +2,6 @@ package main import "fmt" -func main() { +func old_main() { fmt.Println("Hello, World!") } diff --git a/trunc.go b/trunc.go new file mode 100644 index 0000000..733a0d5 --- /dev/null +++ b/trunc.go @@ -0,0 +1,12 @@ +package main + +import "fmt" + +func main() { + var userFloat float32 + fmt.Println("Enter a floating point number: ") + + fmt.Scan(&userFloat) + + fmt.Printf("%.0f", userFloat) +}