/**
 * Calculate the profit margin given the revenue and expenses.
 *
 * @param revenue total revenue earned
 * @param expenses total expenses incurred
 * @return the profit margin as a percentage rounded to two decimal places
 */
fun calculateProfitMargin(revenue: Double, expenses: Double): Double {

    return try {
        val profit = revenue / expenses
        val profitMargin = (profit - 1) * 100
        profitMargin.round(2)
    } catch (e: ArithmeticException) {
        0.00
    }
}

fun Double.round(decimals: Int): Double = "%.${decimals}f".format(this).toDouble()
/**
 * Calculate the profit margin given the revenue and expenses.
 *
 * @param revenue total revenue earned
 * @param expenses total expenses incurred
 * @return the profit margin as a percentage rounded to two decimal places
 */
fun calculateProfitMargin(revenue: Double, expenses: Double): Double {
/**
 * Calculate the profit margin given the revenue and expenses.
 *
 * @param revenue total revenue earned
 * @param expenses total expenses incurred
 * @return the profit margin as a percentage rounded to two decimal places
 */
fun calculateProfitMargin(revenue: Double, expenses: Double): Double {

    return try {
        val profit = revenue / expenses
        val profitMargin = (profit - 1) * 100
        profitMargin.round(2)
    } catch (e: ArithmeticException) {
        0.00
    }
}

fun Double.round(decimals: Int): Double = "%.${decimals}f".format(this).toDouble()