Skip to content

Instantly share code, notes, and snippets.

@loganvolkers
Last active November 11, 2024 15:28
Show Gist options
  • Save loganvolkers/933af8513ed8c2268f59c85a31761a43 to your computer and use it in GitHub Desktop.
Save loganvolkers/933af8513ed8c2268f59c85a31761a43 to your computer and use it in GitHub Desktop.
Byte formatting for Google Sheets
@ns-kbhat
Copy link

ns-kbhat commented Mar 6, 2024

super useful!

@ortarab
Copy link

ortarab commented Apr 3, 2024

Briliant!

@sdruzkin
Copy link

sdruzkin commented Oct 20, 2024

For those working with exa bytes, here is a modified @kaustubhcs' formula working all the way to zetta bytes. It also prints two decimal places. Replace B2 with your cell.

Base 1024

=IF(abs(B2)<1024, B2 & " B", 
	IF(abs(B2)<pow(1024, 2), ROUND(DIVIDE(B2,pow(1024, 1)),2) & " KiB", 
	IF(abs(B2)<pow(1024, 3), ROUND(DIVIDE(B2,pow(1024, 2)),2) & " MiB", 
	IF(abs(B2)<pow(1024, 4), ROUND(DIVIDE(B2,pow(1024, 3)),2) & " GiB", 
	IF(abs(B2)<pow(1024, 5), ROUND(DIVIDE(B2,pow(1024, 4)),2) & " TiB", 
	IF(abs(B2)<pow(1024, 6), ROUND(DIVIDE(B2,pow(1024, 5)),2) & " PiB", 
	IF(abs(B2)<pow(1024, 7), ROUND(DIVIDE(B2,pow(1024, 6)),2) & " EiB", 
	IF(abs(B2)<pow(1024, 8), ROUND(DIVIDE(B2,pow(1024, 7)),2) & " ZiB", 
	"Input is not a number"))))))))

Base 1000

=IF(abs(B2)<1000, B2 & " B", 
	IF(abs(B2)<pow(1000, 2), ROUND(DIVIDE(B2,pow(1000, 1)),2) & " KB", 
	IF(abs(B2)<pow(1000, 3), ROUND(DIVIDE(B2,pow(1000, 2)),2) & " MB", 
	IF(abs(B2)<pow(1000, 4), ROUND(DIVIDE(B2,pow(1000, 3)),2) & " GB", 
	IF(abs(B2)<pow(1000, 5), ROUND(DIVIDE(B2,pow(1000, 4)),2) & " TB", 
	IF(abs(B2)<pow(1000, 6), ROUND(DIVIDE(B2,pow(1000, 5)),2) & " PB", 
	IF(abs(B2)<pow(1000, 7), ROUND(DIVIDE(B2,pow(1000, 6)),2) & " EB", 
	IF(abs(B2)<pow(1000, 8), ROUND(DIVIDE(B2,pow(1000, 7)),2) & " ZB", 
	"Input is not a number"))))))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment