Rounds argument x
to the nearest integer, but round halfway cases away from zero, (regardless of the current rounding
direction), instead of to the nearest even integer like rint.
Remember to link the math library: valac -X -lm ...
Example: Round (double):
public static int main (string[] args) {
// Output:
// ``round (1.3) = 1.0``
// ``round (1.4) = 1.0``
// ``round (1.5) = 2.0``
// ``round (1.6) = 2.0``
print ("round (%.1lf) = %.1lf\n", 1.3, Math.round (1.3));
print ("round (%.1lf) = %.1lf\n", 1.4, Math.round (1.4));
print ("round (%.1lf) = %.1lf\n", 1.5, Math.round (1.5));
print ("round (%.1lf) = %.1lf\n", 1.6, Math.round (1.6));
return 0;
}
valac --pkg glib-2.0 -X -lm GLib.Math.round.vala
x |
A numeric value. |