fix number formats

This commit is contained in:
Simon Ding
2024-08-02 11:14:21 +08:00
parent c787d71fbd
commit 7f8c613a65

View File

@@ -49,7 +49,7 @@ extension FileFormatter on num {
final base = base1024 ? 1024 : 1000;
if (this <= 0) return "0";
final units = ["B", "kB", "MB", "GB", "TB"];
int digitGroups = (log(this) / log(base)).round();
int digitGroups = (log(this) / log(base)).floor();
return "${NumberFormat("#,##0.#").format(this / pow(base, digitGroups))} ${units[digitGroups]}";
}
}