Home »
Golang »
Golang Find Output Programs
Golang Conversions | Find Output Programs | Set 2
This section contains the Golang conversions find output programs (set 2) with their output and explanations.
Submitted by Nidhi, on October 21, 2021
Program 1:
package main
import "fmt"
import "strconv"
func main() {
var str1 string = "123.45"
var str2 string = "456.12"
var num float64
num, _ = strconv.ParseFloat(str1, 64)
fmt.Println("Num1 : ", num)
num, _ = strconv.ParseFloat(str2, 64)
fmt.Println("Num2 : ", num)
}
Output:
Num1 : 123.45
Num2 : 456.12
Explanation:
In the main() function, we created two string variables. Then we converted the created strings into a floating-point number using ParseFloat() function. After that, we printed the result.
Program 2:
package main
import "fmt"
import "strconv"
func main() {
var str1 string = "123"
var str2 string = "456"
var num byte
num, _ = strconv.ParseByte(str1)
fmt.Println("Num1 : ", num)
num, _ = strconv.ParseByte(str2)
fmt.Println("Num2 : ", num)
}
Output:
./prog.go:11:11: undefined: strconv.ParseByte
./prog.go:14:11: undefined: strconv.ParseByte
Explanation:
The above program will generate syntax errors because ParseByte() function is not available in the strconv package.
Golang Find Output Programs »