xxxxxxxxxx
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
xxxxxxxxxx
int roundToInt(double meinDouble) {
double multiplier = .5;
return (multiplier * meinDouble).round();
}
xxxxxxxxxx
//if you work with currency i think you should try NumberFormat
//Using NumberFormat.currency
// A1
print(NumberFormat.currency().format(123456)); // USD123,456.00
// A2
print(NumberFormat.currency(locale: 'eu').format(123456)); // 123.456,00 EUR
// A3
print(NumberFormat.currency(name: 'EURO').format(123456)); // EURO123,456.00
// A4
print(NumberFormat.currency(locale: 'eu', symbol: '?').format(123456)); // 123.456,00 ?
// A5
print(NumberFormat.currency(locale: 'eu', decimalDigits: 3).format(123456)); // 123.456,000 EUR
// A6
print(NumberFormat.currency(locale: 'eu', customPattern: '\u00a4 #,##.#').format(123456)); // EUR 12.34.56,00
//Using NumberFormat.simpleCurrency
// B1
print(NumberFormat.simpleCurrency().format(123456)); // $123,456.00
// B2
print(NumberFormat.simpleCurrency(locale: 'eu').format(123456)); // 123.456,00 €
// B3
print(NumberFormat.simpleCurrency(name: 'EURO').format(123456)); // EURO123,456.00
// B4
print(NumberFormat.simpleCurrency(locale: 'eu', decimalDigits: 3).format(123456)); // 123.456,000 €