From f0eb24a1b722814ed043f30d0445aa386024a93f Mon Sep 17 00:00:00 2001 From: Inuka Wijerathna Date: Fri, 5 Jun 2026 10:46:29 +0530 Subject: [PATCH] Add return on investment to maths --- maths/return_on_investment.dart | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 maths/return_on_investment.dart diff --git a/maths/return_on_investment.dart b/maths/return_on_investment.dart new file mode 100644 index 0000000..f902444 --- /dev/null +++ b/maths/return_on_investment.dart @@ -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 +}