Currency format in dart

后端 未结 5 1992
一向
一向 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:33

    Here's an example from a flutter implementation:

    import 'package:intl/intl.dart';
    
    final formatCurrency = new NumberFormat.simpleCurrency();
    
    new Expanded(
                child: new Center(
                    child: new Text('${formatCurrency.format(_moneyCounter)}',
                      style: new TextStyle(
                        color: Colors.greenAccent,
                        fontSize: 46.9,
                        fontWeight: FontWeight.w800)))),
    

    Results in $#,###.## or $4,100.00 for example.

    Note that the $ in Text('${... is only to reference the variable _moneyCounter inside the ' ' and has nothing to do with the $ added to the formatted result.

提交回复
热议问题