Skip to content

Simple financing app that offers percent change, forex conversions, and mortgage payment calculations.

Notifications You must be signed in to change notification settings

monophosphate/SimpleFinance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

SimpleFinance

A simple financing app that allows you to:

  • find the percent change based on two values
  • convert from the USD to the EUR, JPY, and GBP
  • calculate the monthly payments on a mortgage

Demo

Notes

Under the hood:

These are the variables that allow the app to save user inputs to be used in the later calculations along with default values for currencies.

    //Return Calculator
    @State var before = ""
    @State var after = ""
    
    //Dollar Conversion
    @State var usd = ""
    @State var convert = 0
    let conversionRate = [0.83, 109.13, 0.72]
    let currencyName = ["EUR", "JPY", "GBP"]
    
    //Mortgage Payment
    @State var principal = ""
    @State var rate = ""
    @State var time = ""

The following is how we calculate the percentage change between the two values using (new - old) / old.

var calculateReturn: Double {
        if before == "" || after == "" {
            return 0
        }
        let old = Double(before) ?? 0
        let new = Double(after) ?? 0
        return (new - old) / old * 100
    }

The code below is responsible for taking in our currency variables, and using a Picker, generate the appropriate currency conversion.

TextField("USD", text: $usd)
Picker("Conversion", selection: $convert) {
   ForEach (0 ..< conversionRate.count) {
       Text("\(currencyName[$0])")
   }
}.pickerStyle(SegmentedPickerStyle())
Text("\((Double(usd) ?? 0) * conversionRate[convert], specifier: "%.2f") \(currencyName[convert])")

And the final part, calculating the mortgage monthly payments using (principal * (rate / 12) * (1 + rate / 12)^(time * 12)) / ((1 + rate / 12)^(time * 12) - 1)

    var MortgagePmt: Double {
        if principal == "" || time == "" || rate == "" {
            return 0
        }
        let p = Double(principal) ?? 0
        let t = Double(time) ?? 0
        let r = Double(rate) ?? 0
        return ((p * r / 100 / 12) * pow(1 + r / 100 / 12, t * 12))
            / (pow(1 + r / 100 / 12, t * 12) - 1)
    }

About

Simple financing app that offers percent change, forex conversions, and mortgage payment calculations.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages