ADVERTISEMENT
ADVERTISEMENT

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 »



ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.