Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions maths/return_on_investment.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/// Calculates Return on Investment (ROI) as a percentage.
/// ROI measures the profitability of an investment relative to its cost.
///
/// Formula: ROI = (Gain - Cost) / Cost * 100
///
/// Reference: https://www.investopedia.com/terms/r/returnoninvestment.asp

double returnOnInvestment(
double gainFromInvestment, double costOfInvestment) {
if (costOfInvestment <= 0) {
throw ArgumentError('costOfInvestment must be greater than 0');
}
return (gainFromInvestment - costOfInvestment) / costOfInvestment * 100;
}

void main() {
print(returnOnInvestment(1000, 500)); // 100.0
print(returnOnInvestment(500, 500)); // 0.0
print(returnOnInvestment(200, 500)); // -60.0
}