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

PREVIOUS NEXT
Code Example
Dart :: change padding in text field flutter 
Dart :: flutter text color 
Dart :: canonical tag 
Dart :: height appbar flutter 
Dart :: flutter appbar icon 
Dart :: dart continue 
Dart :: add bg image to scaffold flutter 
Dart :: image fit flutter 
Dart :: target of uri doesn 
Dart :: flutter close dialog 
Dart :: dart find element in list 
Dart :: flutter on build complete 
Dart :: flutter flotingactionbutton 
Dart :: how to disable screen rotation in flutter 
Dart :: dart map foreach 
Dart :: how to disable switch in flutter 
Dart :: flutter flotingactionbutton with text 
Dart :: flutter list dynamic to list int 
Dart :: flutter transform 
Dart :: dart constructor assert 
Dart :: flutter flat button size 
Dart :: dart variable in string 
Dart :: badge flutter 
Dart :: dart comments 
Dart :: input in dart 
Dart :: dart promise all 
Dart :: Flutter dynamic table example 
Dart :: flutter print http response 
Dart :: flutter map key/value 
Dart :: flutter iterate over list widget 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =