I am attempting to create a program where you can input a float32 into a scanner, and have the output be a truncation of the float, removing all digits from the right of the decimal place.
Example:
Input: 6.7777
Output: 6
The problem I'm having with my code is the ParseFloat conversion is rounding up my number instead of truncating the number.
Example:
Input: 6.7777
Output: 7
-This Is My Code-
package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func main() {
scanner := bufio.NewScanner(os.Stdin)
fmt.Printf("Enter Floating Point Number: ")
scanner.Scan()<br />
input, _ := strconv.ParseFloat(scanner.Text(), 64)
fmt.Printf("Floating Point Number Truncated: %.f", input)
}
Any golang savants out there that can help?
I'm starting to think i may be using the wrong functions for my program requirements, can i make this code work? Or do i need to take another approach?
Thank you for any time that can be spared to assist.