Use the decimal type to compute the future value of an investment in CSharp

Description

The following code shows how to use the decimal type to compute the future value of an investment.

Example


using System; //ww  w  . j  a v  a 2  s . com
   
public class MainClass {     
  public static void Main() { 
    decimal amount;   
    decimal rate_of_return;  
    int years, i;   
   
    amount = 100000.0M; 
    rate_of_return = 0.17M; 
    years = 100; 
 
    Console.WriteLine("Original investment: $" + amount); 
    Console.WriteLine("Rate of return: " + rate_of_return); 
    Console.WriteLine("Over " + years + " years"); 
 
    for(i = 0; i < years; i++) {
      amount = amount + (amount * rate_of_return); 
    }
    Console.WriteLine("Future value is $" + amount);  
  } 
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var