nc-photos/app/lib/double_extension.dart

18 lines
466 B
Dart
Raw Normal View History

import 'package:np_common/string_extension.dart';
2021-04-10 06:28:12 +02:00
extension DoubleExtension on double {
/// Same as toStringAsFixed but with trailing zeros truncated
String toStringAsFixedTruncated(int fractionDigits) {
String tmp = toStringAsFixed(fractionDigits);
if (fractionDigits == 0) {
return tmp;
}
tmp = tmp.trimRightAny("0");
if (tmp.endsWith(".")) {
return tmp.substring(0, tmp.length - 1);
} else {
return tmp;
}
}
}