Search
 
SCRIPT & CODE EXAMPLE
 

DART

dart round to 2 decimals

import 'dart:math';

double roundDouble(double value, int places){ 
   double mod = pow(10.0, places); 
   return ((value * mod).round().toDouble() / mod); 
}

main() {
  double num1 = roundDouble(12.3412, 2);
  // 12.34

  double num2 = roundDouble(12.5668, 2);
  // 12.57

  double num3 = roundDouble(-12.3412, 2);
  // -12.34

  double num4 = roundDouble(-12.3456, 2);
  // -12.35
}

OR

double num1 = double.parse((12.3412).toStringAsFixed(2));
// 12.34
Comment

Round double to int flutter

int roundToInt(double meinDouble) {
  double multiplier = .5;
  return (multiplier * meinDouble).round();
}
Comment

PREVIOUS NEXT
Code Example
Dart :: bad state insecure http is not allowed flutter 
Dart :: flutter how to space buttons evenly in a row 
Dart :: dart log to console 
Dart :: Flutter: Setting the height of the AppBar 
Dart :: appbar icon 
Dart :: undeline to text in flutter 
Dart :: how to get value from user in dart 
Dart :: flutter auto height container 
Dart :: flutter portrait only 
Dart :: print variable types in flutter 
Dart :: flutter navigation pop 
Dart :: BoxShadow in DrawerHeader flutter 
Dart :: flutter remove map 
Dart :: flutter dropdownbutton enum 
Dart :: dart list map index 
Dart :: underscore dart 
Dart :: flutter column vertical direction 
Dart :: flutter mirror-inverted widget 
Dart :: round off in dart 
Dart :: flutter ignorepointer 
Dart :: dart trim 
Dart :: at this point the state of the widget element tree is no longer stable. flutter 
Dart :: flutter padding 
Dart :: release apk not working flutter 
Dart :: color textfield text flutter 
Dart :: flutter string to date time 
Dart :: flutter send function as parameter 
Dart :: What is Dart? 
Dart :: dart key value pair list 
Dart :: convert string to file flutter 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =