Logo

Programming-Idioms

History of Idiom 81 > diff from v56 to v57

Edit summary for version 57 by programming-idioms.org:
[Dart] Fix variable names. No sample values. Warning negative numbers.

Version 56

2020-06-19, 03:55:04

Version 57

2020-06-20, 09:55:16

Idiom #81 Round floating point number to integer

Declare integer y and initialize it with the rounded value of floating point number x .
Ties (when the fractional part of x is exactly .5) must be rounded up (to positive infinity).

Idiom #81 Round floating point number to integer

Declare integer y and initialize it with the rounded value of floating point number x .
Ties (when the fractional part of x is exactly .5) must be rounded up (to positive infinity).

Variables
y,x
Variables
y,x
Code
  int x;
  double y = 1.4;
  
  x = y.round();
Code
y = x.round();
Comments bubble
This round ties "away from zero", though.