Q:

Golang Conversions | Find Output Programs | Set 2

belongs to collection: Golang Find Output Programs

0

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)
}

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)
}

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer Program 1:

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.


 

Answer Program 2:

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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Golang Find Output Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Golang Date & Time | Find Output Programs | Set 1... >>
<< Golang Conversions | Find Output Programs | Set 1...