Dart - NumberFormat

后端 未结 7 1014
北荒
北荒 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:41

    Edit: The solution posted by Martin seens to be a better one

    I don't think this can be done directly. You'll most likely need something like this:

    final f = new NumberFormat("###.00");
    
    String format(num n) {
      final s = f.format(n);
      return s.endsWith('00') ? s.substring(0, s.length - 3) : s;
    }
    

提交回复
热议问题