Home > other >  Bosses to help answer the next question, define a class unit, unit conversion, addition and subtract
Bosses to help answer the next question, define a class unit, unit conversion, addition and subtract

Time:04-13

Bytes per unit converts kib, mib, gib (1 kib=1024 bytes, and so on)
Define a class unit, unit conversion, addition and subtraction function between different units, and can directly print out the results
Kib print (unit (" 1 ") + unit (" 2 kib "))
> 3 kib

CodePudding user response:

Give you a way for your reference,

Def size_convert (value) : # file size conversion unit
Units=[" B ", "KB", "MB", "GB" and "TB", "PB"]
Size=1024.0
For I in range (len (units) :
If (the value/size) & lt; 1:
"Return" % 2 f % s % (value, units [I])
Value=HTTP://https://bbs.csdn.net/topics/value/size
  • Related