{

# Golang example How to calculate future compound interest It is a short tutorial about how to calculate compound interest in the go language.

## Golang Compound Interest example program

Compound interest is used in the calculating value of an amount in investment and finance domains.

Compound interest is an interest applied to the principal, the period for the period. In mathematical terms, Compound interest has a formula as seen below.

``````Future Compound Interest Amount = principal × ((interest rate/100)+1) power of number
Interest Amount = Future Compound Interest Amount - Amount
``````
• principal: principal amount

• Interest rate: It is a percentage value (%)

• the number is a period of years

Let’s write a program to calculate compound interest in the go language In a program code,

• User enters an input of principal amount, interest, and Period from the console
• save all these values in a temporary variable
• Calculate future amount and compound interest amount using the above formula
• Finally, print the result

Here is the golang program code to calculate simple interest.

``````package main

import (
"fmt"
)

func main() {
var principal, interest, period, total compountInterest float64;
fmt.Scanln(&principal)
fmt.Scanln(&interest)

fmt.Scanln(&period)

futureAmount= principal* (math.Pow((1 + interest/100), period))
compountInterest = futureAmount- principal

fmt.Println("\nCompound Interest  Amount: ", compountInterest )
fmt.Println("\n Total  Future Amount: ", futureAmount)

}
``````

Output:

``````Please enter principal amount: 10000
nCompound Interest  Amount: 72850
Total  Future Amount: 1.797010299914431e+61
``````

This program takes an input - principal, rate of interest, and period in years and stores these values in a variable.

Calculated the future and compound interest and returns the total amount.

## Conclusion

In this example, You learned to calculate compound interest principal amount in the Go language.

Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

Similar Posts
Subscribe
You'll get a notification every time a post gets published here.

Related posts