/**
 * Function to round a given floating-point number to the nearest integer.
 *
 * @param num The floating-point number to be rounded.
 * @return The rounded integer value.
 *
 * Advantages:
 * - Rounding floating-point numbers to integers can help in cases where a more precise value is not necessary.
 * - Rounded integers are often used in civil engineering calculations to simplify the results.
 *
 * Difficulty level: Difficult
 */
fun roundToNearestInteger(num: Double): Int {

    // Convert the floating-point number to a string representation
    val numStr = num.toString()

    // Check if the number contains a decimal point
    if ('.' in numStr) {
        // Split the number into two parts: integer part and decimal part
        val (integerPart, decimalPart) = numStr.split('.')

        // Convert the integer part back to an integer
        var integerPartInt = integerPart.toInt()

        // Check if the decimal part is greater than or equal to 0.5
        if (decimalPart.toInt() >= 5) {
            // Round up by incrementing the integer part by 1
            integerPartInt++
        }

        // Return the rounded integer
        return integerPartInt
    }

    // If the number is already an integer, return it directly
    return num.toInt()
}
/**
 * Function to round a given floating-point number to the nearest integer.
 *
 * @param num The floating-point number to be rounded.
 * @return The rounded integer value.
 *
 * Advantages:
 * - Rounding floating-point numbers to integers can help in cases where a more precise value is not necessary.
 * - Rounded integers are often used in civil engineering calculations to simplify the results.
 *
 * Difficulty level: Difficult
 */
fun roundToNearestInteger(num: Double): Int {
/**
 * Function to round a given floating-point number to the nearest integer.
 *
 * @param num The floating-point number to be rounded.
 * @return The rounded integer value.
 *
 * Advantages:
 * - Rounding floating-point numbers to integers can help in cases where a more precise value is not necessary.
 * - Rounded integers are often used in civil engineering calculations to simplify the results.
 *
 * Difficulty level: Difficult
 */
fun roundToNearestInteger(num: Double): Int {

    // Convert the floating-point number to a string representation
    val numStr = num.toString()

    // Check if the number contains a decimal point
    if ('.' in numStr) {
        // Split the number into two parts: integer part and decimal part
        val (integerPart, decimalPart) = numStr.split('.')

        // Convert the integer part back to an integer
        var integerPartInt = integerPart.toInt()

        // Check if the decimal part is greater than or equal to 0.5
        if (decimalPart.toInt() >= 5) {
            // Round up by incrementing the integer part by 1
            integerPartInt++
        }

        // Return the rounded integer
        return integerPartInt
    }

    // If the number is already an integer, return it directly
    return num.toInt()
}