Skip to content
This repository was archived by the owner on Feb 9, 2022. It is now read-only.

Commit c31132a

Browse files
ExplvExplv
authored andcommitted
Use DecimalFormat for RSUnits
1 parent 9d7d734 commit c31132a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

AIO/src/org/aio/util/RSUnits.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package org.aio.util;
22

3+
import java.text.DecimalFormat;
34
import java.util.*;
45
import java.util.regex.Pattern;
56

67
public class RSUnits {
78

89
public static final Pattern UNIT_PATTERN = Pattern.compile("^\\d+(?:(?:\\.\\d+[kmb])|[kmb])?$");
910

11+
private static final DecimalFormat decimalFormat = new DecimalFormat("#.###");
12+
1013
private static final Map<Character, Integer> suffixMultipliers;
1114
static {
1215
// Use a LinkedHashMap to maintain insertion order (largest denomination first)
@@ -45,7 +48,9 @@ public static String valueToFormatted(final long value) {
4548
Integer multiplier = suffixMultipliers.get(suffix);
4649

4750
if (value > multiplier) {
48-
return String.format("%.2f" + suffix, ((double) value / multiplier));
51+
double newValue = ((double) value / multiplier);
52+
53+
return decimalFormat.format(newValue) + suffix;
4954
}
5055
}
5156

0 commit comments

Comments
 (0)