I am complete noob to scripts, java and all things code but i need to get a script working on a google spreadsheet of mine.
Its a file inventory and I need to convert raw bytes to KB, MB,GB.
I tried a formatting ajustment on the cells themselves but that gave me incorrect calculations something to do with 1000 vs 1024 values
I have a script that works im just not sure how to get it into my spreadsheet.
(Spare me corretions on my improper use of coding grammar, I am not trying to become a better coder I just want to get this thing working...)
Here's what I want to implement to my google sheet
function formatBytes(bytes, decimals = 2) {
if (bytes === 0) return '0 Bytes';
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
}
Can anyone help?
question from:
https://stackoverflow.com/questions/65884922/looking-to-apply-a-functioning-kb-mb-gb-script-to-specific-column-in-google-she 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…