This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathConversions.swift
74 lines (61 loc) · 2.13 KB
/
Conversions.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
// Conversions.swift
// Weather Test App
//
// Created by Michael Pulsifer on 8/3/14.
// U.S. Department of Labor.
//
// The various parameter names may seem odd, but this was originally created for OSHA Heat Safety v.2.0
import Foundation
class Conversions {
// Convert from F to C (Integer)
func fahrenheitToCelsius(tempInF:Int) ->Int {
let celsius = (tempInF - 32) * (5/9)
return celsius as Int
}
// Convert from F to C (Double)
func fahrenheitToCelsius(tempInF:Double) ->Double {
let celsius = (tempInF - 32.0) * (5.0/9.0)
return celsius as Double
}
// Convert from C to F (Integer)
func celsiusToFahrenheit(tempInC:Int) ->Int {
let fahrenheit = (tempInC * 9/5) + 32
return fahrenheit as Int
}
// Convert from C to F (Integer)
func celsiusToFahrenheit(tempInC:Double) ->Double {
let fahrenheit = (tempInC * 9.0/5.0) + 32.0
return fahrenheit as Double
}
// Convert from miles to kilometers (Integer)
func milesToKilometers(speedInMPH:Int) ->Int {
let speedInKPH = speedInMPH * 1.60934
return speedInKPH as Int
}
// Convert from miles to kilometers (Double)
func milesToKilometers(speedInMPH:Double) ->Double {
let speedInKPH = speedInMPH * 1.60934
return speedInKPH as Double
}
// Convert from kilometers to miles (Integer)
func kilometersToMiles(speedInKPH:Int) ->Int {
let speedInMPH = speedInKPH / 1.60934
return speedInMPH as Int
}
// Convert from kilometers to miles (Double)
func kilometersToMiles(speedInMPH:Double) ->Double {
let speedInKPH = speedInMPH / 1.60934
return speedInKPH as Double
}
// Convert from inches to cm
func inchesToCentimeters(depthInInches:Double) ->Double {
let depthInCentimeters = depthInInches * 2.54
return depthInCentimeters as Double
}
// Convert from cm to inches
func centimetersToInches(depthInCentimeters:Double) ->Double {
let depthInInches = depthInCentimeters / 2.54
return depthInInches as Double
}
}