MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / add_binary_prefix

Function add_binary_prefix

conversions/prefix_conversions_string.py:103–115  ·  view source on GitHub ↗

Function that converts a number to his version with Binary prefix @input value (an integer) @example: >>> add_binary_prefix(65536) '64.0 kilo'

(value: float)

Source from the content-addressed store, hash-verified

101
102
103def add_binary_prefix(value: float) -> str:
104 """
105 Function that converts a number to his version with Binary prefix
106 @input value (an integer)
107 @example:
108 >>> add_binary_prefix(65536)
109 '64.0 kilo'
110 """
111 for prefix in BinaryUnit:
112 numerical_part = value / (2**prefix.value)
113 if numerical_part > 1:
114 return f"{numerical_part!s} {prefix.name}"
115 return str(value)
116
117
118if __name__ == "__main__":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected