Various types of string conversions are needed while performing tasks in Golang. Package strconv is imported to perform conversions to and from string.
String to Boolean Conversion
ParseBool is used to convert string to boolean value. It accepts 1, t, T, TRUE, true, True as true and 0, f, F, FALSE, false, False as false. Any other value returns an error and will display the value as false.
Before : string String value is: GeeksforGeeks After : bool Boolean value is: false Before : string String value is: t After : bool Boolean value is: true Before : string String value is: 0 After : bool Boolean value is: false
String to Integer Conversion
ParseInt function is used to convert string to an integer value. It interprets a string in the given base (0, 2 to 36) and bit size (0 to 64) and returns the corresponding value.
Before : string String value is: GeeksforGeeks After : int64 Integer value is: 0 Before : string String value is: 100 After : int64 Integer value is: 100
String to Float Conversion
ParseFloat is used to convert the string to float type with the precision specified by bitSize: 32 for float32, or 64 for float64. When bitSize=32, the result still has type float64, but it will be convertible to float32 without changing its value.
Before : string String value is: 3.1415926535 After : float64 Float value is: 3.1415926535 Before : string String value is: 3.1415926535 After : float64 Float value is: 3.1415927410125732
- How to fetch an Integer variable as String in GoLang?
- How to Convert string to float type in Golang?
- Different Ways to Find the Type of Variable in Golang
- How to Convert string to integer type in Golang?
- How to convert Int data type to Float in Golang?
- Java Program to convert boolean to integer
- Atomic Variable in Golang
- Golang program that uses func with variable argument list
- How to declare and access pointer variable in Golang?
- Golang Program that uses func as Local Variable
- PHP | Converting string to Date and DateTime
- How to get cookies from curl into a variable in PHP ?
- How to add a method to struct type in Golang?
- Different Ways to Find the Type of an Object in Golang
- How to find the type of Struct in Golang?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.