From the course: Learning Go
Unlock this course with a free trial
Join today to access over 24,200 courses taught by industry experts.
Use math operators - Go Tutorial
From the course: Learning Go
Use math operators
- [Instructor] Go supports the same set of mathematical operators that work in other C-style languages, including the usual math operators for addition, subtraction, multiplication, and division, and you also get all of the Bitwise operators that are available in C and Java. As I've mentioned previously, Go doesn't implicitly convert numeric types. So you can't take an integer value and, say, add it to a floating point value without conversion. In this code, I have one variable that's an integer and another one that's a float, and I try to add them together. This will result in an error, crashing the application, and I'll see the error message, invalid operation. To correctly add these values together, I have to convert one of the values to match the type of the other one. And you do this by wrapping the value in a function that has the same name as the target type. So now once again, I'm starting off with an integer…
Contents
-
-
-
-
Explore Go's variable types3m 16s
-
(Locked)
Declare and initialize variables5m 55s
-
(Locked)
Get input from the console3m 22s
-
(Locked)
Convert string inputs to other types4m 10s
-
(Locked)
Use math operators2m 3s
-
(Locked)
Use the math package5m 20s
-
(Locked)
Work with dates and times3m 50s
-
(Locked)
Solution: Create a simple calculator app2m 26s
-
-
-
-
-
-