Can I format a number before it is rendered in

后端 未结 4 1550
后悔当初
后悔当初 2021-01-07 20:24

I am rendering a node in Flutter app something like:

We have total ${_summary[\'bookCount\']} books. 

_summ

4条回答
  •  死守一世寂寞
    2021-01-07 21:07

    An update for above answers:

    First add intl package into your pubspec.yaml file, just after flutter sdk (like below):

        dependencies:
          flutter:
            sdk: flutter
          intl: ^0.16.0
    

    If you use flutter_localizations, intl must be above of that.

    Now you can use NumberFormat class.

    Some examples:

    print(NumberFormat.currency().format(123456)); // USD123,456.00
    
    print(NumberFormat.currency(locale: 'eu').format(123456)); // 123.456,00 EUR
    
    print(NumberFormat.currency(name: 'EURO').format(123456)); // EURO123,456.00
    
    print(NumberFormat.currency(locale: 'eu', symbol: '?').format(123456)); // 123.456,00 ?
    
    print(NumberFormat.currency(locale: 'eu', decimalDigits: 3).format(123456)); // 123.456,000 EUR
    
    print(NumberFormat.currency(locale: 'eu', customPattern: '\u00a4 #,##.#').format(123456)); // EUR 12.34.56,00
    
    • Refrence & More information: https://www.woolha.com/tutorials/dart-formatting-currency-with-numberformat#supported-locales

    • NumberFormat Class Dart API: https://api.flutter.dev/flutter/intl/NumberFormat-class.html

提交回复
热议问题