Logo

Programming-Idioms

History of Idiom 81 > diff from v61 to v62

Edit summary for version 62 by programming-idioms.org:
[Dart] +DocURL

Version 61

2020-11-05, 15:19:44

Version 62

2020-11-05, 15:20:51

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
var y = x.round();
Code
var y = x.round();
Comments bubble
This rounds ties "away from zero", though.
Comments bubble
This rounds ties "away from zero", though.
Doc URL
https://api.dart.dev/stable/2.10.3/dart-core/double/round.html
Demo URL
https://dartpad.dev/32508506d144cbed2e5a90a6f5b06d20
Demo URL
https://dartpad.dev/32508506d144cbed2e5a90a6f5b06d20