Last active
February 11, 2019 14:39
-
-
Save mesuutt/f5ee086f2685cb3f986b5c74a0459a03 to your computer and use it in GitHub Desktop.
Format money as Turkish money format in dart language
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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