Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

dart
communitycreator

What is the round() method in Dart?

Maria Elijah

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

To round a double value to an int value in Dart, the method round() is used.

The round() method returns the value of a number rounded to the nearest integer.

Syntax

num.round()

Parameter

The method round() takes no parameter.

Return type

This method returns the value of a number rounded to the nearest integer.

Code

The following code shows how to use the method round() in Dart:

void main() {
//converting to nearest int value
int num = (-2.3).round();
print('The temperature is ${num} in Texas');
int num2 = (-2.5).round();
print(num2);
double n1 = 12.023;
double n2 = 12.89;
// compares if values are equal
if (n1.round() == n2.round()){
print('There are 12 apples in the basket');
}
else {
print('Not equal');
}
// display result
var value = n1.round();
print( value );
value = n2.round();
print( value );
}

RELATED TAGS

dart
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring