I was trying out this bytes conversion code that was posted over the PB forum.
I can't seem to figure out how to make it behave in the manner detailed in the code. Hope someone can figure this out.
Code: Select all
Procedure.s bytecalc(byte.q, NbDecimals.l=0)
Protected unit.b = Round(Log(byte)/Log(1024), 0)
ProcedureReturn StrD(byte/Pow(1024, unit), NbDecimals*(unit & 1))+" "+StringField("Byte,KB,MB,GB,TB,PB,EB", unit+1, ",")
EndProcedure
Debug bytecalc(50)
Debug bytecalc(1024) + " <---- 1,024bytes = 1KB"
Debug bytecalc(1536) + " <---- 1,536bytes = 1.50KB instead of the shown 2KB result"
Debug bytecalc(2047) + " <---- 2,047bytes = 1.99KB instead of the shown 2KB result"
Debug bytecalc(2048) + " <---- 2,048bytes = 2KB <----This is 2KB"
Debug bytecalc(1048576 ) + " <---- 1,048,576bytes = 1MB"
Debug bytecalc(1073741824) + " <---- 1,073,741,824bytes = 1GB instead of the shown 1024MB result"
Debug bytecalc(1099511627776) + " <---- 1,099,511,627,776bytes = 1TB"
Debug bytecalc(1125899906842624) + " <---- 1,125,899,906,842,624bytes = 1PB"