devel flutt
devel flutt

Reputation: 25

Flutter convert currency format

for example +100286020524,17 how to become Rp 100.286.020.524,17 and remove this sign + . how to implement in dart flutter

EDIT
this mycode I using indonesia: 1.0.1 packages

main() {
  rupiah(123456789); // Rp 123,456,789
}

I've tried like this:

replaceAll(new RegExp(r'[^\w\s]+'),'')

but not i hope output. how to remove symbol plus

Upvotes: 1

Views: 13354

Answers (1)

huextrat
huextrat

Reputation: 432

To easily format values according to a locale it is recommended to use intl.

A currency can be formatted like this for Indonesia:

double d = 100286020524.17;
final currencyFormatter = NumberFormat.currency(locale: 'ID');
print(currencyFormatter.format(d)); // IDR100.286.020.524,17

You can also use classic formatting:

double d = 100286020524.17;
final currencyFormatter = NumberFormat('#,##0.00', 'ID');
print(currencyFormatter.format(d)); // 100.286.020.524,17

In this second way you will have only the value formatted without the currency symbol.

Upvotes: 8

Related Questions