/**
 * Calculate the commission rate based on the total sales and target sales.
 *
 * @param totalSales total sales achieved
 * @param targetSales target sales to be achieved
 * @return The commission rate as a percentage rounded to two decimal places.
 */
fun calculateCommissionRate(totalSales: Double, targetSales: Double): Double {

    return try {
        val salesGrowth = (totalSales - targetSales) / targetSales
        val commissionRate = Math.abs(salesGrowth) * 100
        commissionRate.round(2)
    } catch (e: ArithmeticException) {
        0.00
    }
}

fun Double.round(decimals: Int): Double {
    var multiplier = 1.0
    repeat(decimals) { multiplier *= 10 }
    return kotlin.math.round(this * multiplier) / multiplier
}
/**
 * Calculate the commission rate based on the total sales and target sales.
 *
 * @param totalSales total sales achieved
 * @param targetSales target sales to be achieved
 * @return The commission rate as a percentage rounded to two decimal places.
 */
fun calculateCommissionRate(totalSales: Double, targetSales: Double): Double {
/**
 * Calculate the commission rate based on the total sales and target sales.
 *
 * @param totalSales total sales achieved
 * @param targetSales target sales to be achieved
 * @return The commission rate as a percentage rounded to two decimal places.
 */
fun calculateCommissionRate(totalSales: Double, targetSales: Double): Double {

    return try {
        val salesGrowth = (totalSales - targetSales) / targetSales
        val commissionRate = Math.abs(salesGrowth) * 100
        commissionRate.round(2)
    } catch (e: ArithmeticException) {
        0.00
    }
}

fun Double.round(decimals: Int): Double {
    var multiplier = 1.0
    repeat(decimals) { multiplier *= 10 }
    return kotlin.math.round(this * multiplier) / multiplier
}