Currently I have a function to convert bytes too TB.
I am using the below formula to convert.
const formatBytesToTB = (a, b = 2) => {
if (a === 0) {
return "0 TB";
}
return (a / 1099511627776).toFixed(b) + " TB";
};
console.log(formatBytesToTB(109213384704));
The above function is working fine for most of the values that it accepts as bytes
I see some error when bytes value is less than 1 TB.
For example when the input is "109213384704” the function returns “0.10 TB”
Expected output should be “0.09”
I have seen few online converters to test what they return, Google returns 0.10 but rest of the converters show 0.09
Is the function doing right thing ?
0.099if I'm not wrong. What about using.toPrecisioninstead of.toFixed?bto be bigger, like 10 and see then. Seems like rounding problem