Skip to content

Instantly share code, notes, and snippets.

@mesuutt
Last active February 11, 2019 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mesuutt/f5ee086f2685cb3f986b5c74a0459a03 to your computer and use it in GitHub Desktop.
Save mesuutt/f5ee086f2685cb3f986b5c74a0459a03 to your computer and use it in GitHub Desktop.
Format money as Turkish money format in dart language
String formatMoney(dynamic text) {
if (text is num){
text = text.toStringAsFixed(2);
}
return text
.toString()
.replaceAllMapped(RegExp(r"(\d)(?=(\d{3})+\.)"), (m) => "${m.group(1)}.")
.replaceAllMapped(RegExp(r"\.(\d+)$"), (m) => ",${m.group(1)}");
}
formatMoney(0); // 0,00
formatMoney(1234567); // 1.234.567,00
formatMoney(1234567.99); // 1.234.567,99
formatMoney("1234567.99"); // 1.234.567,99
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment