Skip to content

Commit 6cffb42

Browse files
author
Stancu Florin
committed
show 2 decimals for TransformDataUnits
1 parent 9b8140a commit 6cffb42

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed
+10-10
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
package measurements
22

33
// TransformDataUnits converts data units to bytes and determines the appropriate unit (MB, GB, TB, PB)
4-
// Returns the transformed value and the unit as a string
5-
func TransformDataUnits(value int64) (int64, string) {
4+
// Returns the transformed value with 2 decimal places and the unit as a string
5+
func TransformDataUnits(value int64) (float64, string) {
66
// Convert to bytes: value * 1000 * 512 (1000 units of 512 byte data units)
77
// According to NVMe spec: "This value is reported in thousands (i.e., a value of 1 corresponds to 1000 units of 512 bytes read)"
88
bytes := float64(value) * 1000 * 512
99

1010
if bytes < 1000*1000*1000 {
11-
// Less than 1 GB, show in MB
12-
return int64(bytes / 1000 / 1000), "MB"
11+
// Less than 1 GB, show in MB with 2 decimal places
12+
return float64(int64((bytes / 1000 / 1000) * 100)) / 100, "MB"
1313
} else if bytes < 1000*1000*1000*1000 {
14-
// Less than 1 TB, show in GB
15-
return int64(bytes / 1000 / 1000 / 1000), "GB"
14+
// Less than 1 TB, show in GB with 2 decimal places
15+
return float64(int64((bytes / 1000 / 1000 / 1000) * 100)) / 100, "GB"
1616
} else if bytes < 1000*1000*1000*1000*1000 {
17-
// Less than 1 PB, show in TB
18-
return int64(bytes / 1000 / 1000 / 1000 / 1000), "TB"
17+
// Less than 1 PB, show in TB with 2 decimal places
18+
return float64(int64((bytes / 1000 / 1000 / 1000 / 1000) * 100)) / 100, "TB"
1919
} else {
20-
// Show in PB
21-
return int64(bytes / 1000 / 1000 / 1000 / 1000 / 1000), "PB"
20+
// Show in PB with 2 decimal places
21+
return float64(int64((bytes / 1000 / 1000 / 1000 / 1000 / 1000) * 100)) / 100, "PB"
2222
}
2323
}

0 commit comments

Comments
 (0)