Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Converting bytes into KB,MB,GB,TB,PB
#2
Created this small function a long time ago:

Code: (Select All)
Print formatFileSize$(123122555552344566)
Print formatFileSize$(234855666)
Print formatFileSize$(6000234855666)
Print formatFileSize$(512445666)
Print formatFileSize$(512)
Print formatFileSize$(14265444444)
Print formatFileSize$(1355)

Function formatFileSize$ (ts As _Unsigned _Integer64)
t! = ts: i% = 0
Do While t! > 1024
i% = i% + 1: t! = t! / 1024
Loop
If i% > 0 Then
formatFileSize$ = _ToStr$(t!, 2 + Int(Log(t!) / Log(10))) + " " + Mid$("KMGTP", i%, 1) + "B"
Else
formatFileSize$ = _ToStr$(t!) + " B"
End If
End Function
45y and 2M lines of MBASIC>BASICA>QBASIC>QBX>QB64 experience
Reply


Messages In This Thread
RE: Converting bytes into KB,MB,GB,TB,PB - by mdijkens - 05-30-2025, 02:58 PM



Users browsing this thread: 1 Guest(s)