

In this example we have used oct_num variable to store the result. Pass the integer value that you wish to convert as the first argument to the function and the base value as the second argument to the function. In this example to convert integer to octal we will be using strconv.FormatInt() function. Then we need to initialize a 64 bit integer type variable to store the integer value that we wish to convert into octal. fmt package allows us to print anything on the screen whereas strconv method contains the functions which we can use to convert a decimal number to octal number. Output Decimal number 15 is converted to octal as 17ĭecimal number 34 is converted to octal as 42ĭecimal number 26 is converted to octal as 32įirst we have to import fmt package and the strconv package. Example 1: Go Language Program to convert Decimal Number to Octal using Library Function Syntax func FormatInt(input int64, base int) stringįor The base value means the number of digits required to represent the numeric value. When we say convert the decimal number to octal, it means to convert the number with the base value 10 to the base value 8.

For this we are going to use the FormatInt() function of strconv package. In this article you will know how to convert the decimal number to octal in Go language.
