toCurrency method

String toCurrency()

Implementation

String toCurrency() {
  final value = double.tryParse(this) ?? 0.0;
  return "R\$ ${value.toStringAsFixed(2).replaceAll('.', ',')}"
      .replaceAllMapped(RegExp(r'(\d{1,3})(?=(\d{3})+(?!\d))'), (Match m) => '${m[1]}.');
}