Convert an integer into a float64 by writing the destination type like a function:
Go code
count := 3
decimalCount := float64(count)
fmt.Println(decimalCount)Line-by-line explanation
- Count is inferred as int.
float64(count)creates a decimal-number value.- DecimalCount stores the converted value.
- Println displays it.
Expected output
3Println may display a whole-looking 3 even though the stored type is float64.
Converting a float64 to int removes the decimal part; it does not round:
Go code
price := 4.9
whole := int(price)
fmt.Println(whole)Line-by-line explanation
- Price is inferred as float64.
int(price)creates an integer.- The fractional part is discarded.
- Println displays 4.
Expected output
4The result is truncated toward zero, not rounded to 5.
Converting numbers to written decimal text requires formatting tools introduced later. string(65) does not produce "65"; it represents the Unicode character A.