Currency format in dart

后端 未结 5 1973
一向
一向 2020-12-17 07:52

In C# I can do:

12341.4.ToString(\"##,#0.00\")

and the result is 12,345.40

What\'s the equivalent in dart?

5条回答
  •  时光说笑
    2020-12-17 08:26

    I use it. it's working for me

    class MoneyFormat {
     String price;
    
     String moneyFormat(String price) {
      if (price.length > 2) {
      var value = price;
      value = value.replaceAll(RegExp(r'\D'), '');
      value = value.replaceAll(RegExp(r'\B(?=(\d{3})+(?!\d))'), ',');
      return value;
      }
     }
    }
    

    and in TextFormField

    onChanged: (text) {
     priceController.text = moneyFormat.moneyFormat(priceController.text);
    }
    

提交回复
热议问题