1
1
package measurements
2
2
3
3
// 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 ) {
6
6
// Convert to bytes: value * 1000 * 512 (1000 units of 512 byte data units)
7
7
// According to NVMe spec: "This value is reported in thousands (i.e., a value of 1 corresponds to 1000 units of 512 bytes read)"
8
8
bytes := float64 (value ) * 1000 * 512
9
9
10
10
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"
13
13
} 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"
16
16
} 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"
19
19
} 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"
22
22
}
23
23
}
0 commit comments