Skip to content

Commit 8283f8d

Browse files
authored
Fix total return computing (#13)
1 parent 71166f8 commit 8283f8d

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

Sources/Grodt/DTOs/DTOMappers/InvestmentDTOMapper.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,7 @@ class InvestmentDTOMapper {
8989
}
9090

9191
private func calculateTotalReturn(profit: Decimal, cost: Decimal) -> Decimal {
92-
guard cost != 0 else { return 0 }
93-
var totalReturn = profit / cost
94-
var roundedReturn = Decimal()
95-
NSDecimalRound(&roundedReturn, &totalReturn, 2, .bankers)
96-
return roundedReturn
92+
guard cost > 0 else { return 0 }
93+
return (profit / cost).rounded(to: 2)
9794
}
9895
}

Sources/Grodt/DTOs/DTOMappers/PortfolioDTOMapper.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ actor Financials {
9393
}
9494
}
9595

96-
fileprivate extension Decimal {
96+
extension Decimal {
9797
func rounded(to scale: Int, roundingMode: NSDecimalNumber.RoundingMode = .bankers) -> Decimal {
9898
var value = self
9999
var result = Decimal()

0 commit comments

Comments
 (0)