toFormatNumber static method
dynamic
toFormatNumber(
- String valor, {
- int? qtCasasDecimais,
})
Implementation
static toFormatNumber(String valor, {int? qtCasasDecimais}) {
if (valor == 'NaN') return '0,00';
if (valor == 'null') return '0,00';
valor = valor.replaceAll(",", ".");
try {
var numberFormat = NumberFormat("#,##0.00", "pt_BR");
if (qtCasasDecimais != null) numberFormat = NumberFormat("#,##${double.parse('0.0').toStringAsFixed(qtCasasDecimais)}", "pt_BR");
valor = numberFormat.format(double.parse(valor));
} catch (e) {
valor = '0,00';
}
//valor = valor.replaceAll(".", "0,");
//if (valor == 'NaN') return '0,00';
return valor;
}