The OpenD Programming Language

roundTo

Rounded conversion from floating point to integral.

Rounded conversions do not work with non-integral target types.

template roundTo(Target)
Target
roundTo
(
Source
)
(
Source value
)

Examples

assert(roundTo!int(3.14) == 3);
assert(roundTo!int(3.49) == 3);
assert(roundTo!int(3.5) == 4);
assert(roundTo!int(3.999) == 4);
assert(roundTo!int(-3.14) == -3);
assert(roundTo!int(-3.49) == -3);
assert(roundTo!int(-3.5) == -4);
assert(roundTo!int(-3.999) == -4);
assert(roundTo!(const int)(to!(const double)(-3.999)) == -4);

Meta