-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathmain.go
More file actions
25 lines (20 loc) · 660 Bytes
/
main.go
File metadata and controls
25 lines (20 loc) · 660 Bytes
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
package main
import (
"fmt"
"math"
)
func getNamedStockPriceChange(prevPrice, currentPrice float64) (change, percentChange float64) {
change = currentPrice - prevPrice
percentChange = (change / prevPrice) * 100
return
}
func main() {
prevStockPrice := 100000.0
currentStockPrice := 90000.0
change, percentChange := getNamedStockPriceChange(prevStockPrice, currentStockPrice)
if change < 0 {
fmt.Printf("The Stock Price decreased by $%.2f which is %.2f%% of the prev price\n", math.Abs(change), math.Abs(percentChange))
} else {
fmt.Printf("The Stock Price increased by $%.2f which is %.2f%% of the prev price\n", change, percentChange)
}
}