Snippet. Vala. Rounding Double to Int

This is a small Vala function to round doubles to integers.

//======================== START OF FUNCTION ==========================//
// FUNCTION: round_double_to_int                                       //
//=====================================================================//
int round_double_to_int(double dbl) {
    (dbl > 0) ? (dbl += 0.5) : (dbl += (-0.5));
    return (int)dbl;
}
//=====================================================================//
// FUNCTION: round_double_to_int                                       //
//========================= END OF FUNCTION ===========================//

Updated on: 19 Apr 2024