How to convert number to Indian Format in Dart

Adnan Kazi
1 min readApr 6, 2021

Currency number format conversion is very important in any application related to finance.

1234567 => 1,23,45,678

Hi there, this is my very first article, I just experienced something which most of the flutter developers are struggling with, I personally faced these issues now I am sharing with you.

As you can see there are lots of applications in the market which has this feature money conversion to Indian format.

As with any other Logic, we also need to do some basic logic from converting String from one format to another.

Steps:

  1. Open Dartpad dartpad.dev
  2. Make function outside main()
// main function or from where you want to callvoid main() {
print(convert("12345678")) // This will output - 1,23,45,678
}
// conversion functionString convert(String val) {
var lastThree = val.substring(val.length - 3);
var otherNumbers = val.substring(0, val.length - 3);
if (otherNumbers != '') lastThree = ',$lastThree';
var res = otherNumbers.replaceAll(RegExp(r'\B(?=(\d{2})+. (?!\d))'), ',') + lastThree;
return '$res';
}

3. Run code

Yes you did it it was as simple as it was 🥳🥳🥳

Thank you for reading this. If you have any doubts about this article comment below.

--

--