strings.dart 486 B

1234567891011121314151617
  1. formatSize(double? value, {int fixed = 2}) {
  2. if (value == 0) return "0M";
  3. List<String> unitArr = ['B', 'K', 'M', 'G'];
  4. int index = 0;
  5. while (value! > 1024) {
  6. index++;
  7. value = value/ 1024;
  8. }
  9. String size = value.toStringAsFixed(fixed);
  10. return size + unitArr[index];
  11. }
  12. toString(double? value, {int fractionDigits = 1}){
  13. if(value == null)return "";
  14. if(value.toInt() == value)return value.toStringAsFixed(0);
  15. else return value.toStringAsFixed(fractionDigits);
  16. }