Dart - NumberFormat

后端 未结 7 1044
北荒
北荒 2021-02-19 00:08

Is there a way with NumberFormat to display :

  • \'15\' if double value is 15.00
  • \'15.50\' if double value is 15.50

Thanks for yo

7条回答
  •  盖世英雄少女心
    2021-02-19 00:48

    Maybe you don't want use NumberFormat:

    class DoubleToString {
      String format(double toFormat) {
        return (toFormat * 10) % 10 != 0 ?
          '$toFormat' :
          '${toFormat.toInt()}';
      }
    }
    

提交回复
热议问题