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

Function add_si_prefix

conversions/prefix_conversions_string.py:87–100  ·  view source on GitHub ↗

Function that converts a number to his version with SI prefix @input value (an integer) @example: >>> add_si_prefix(10000) '10.0 kilo'

(value: float)

Source from the content-addressed store, hash-verified

85
86
87def add_si_prefix(value: float) -> str:
88 """
89 Function that converts a number to his version with SI prefix
90 @input value (an integer)
91 @example:
92 >>> add_si_prefix(10000)
93 '10.0 kilo'
94 """
95 prefixes = SIUnit.get_positive() if value > 0 else SIUnit.get_negative()
96 for name_prefix, value_prefix in prefixes.items():
97 numerical_part = value / (10**value_prefix)
98 if numerical_part > 1:
99 return f"{numerical_part!s} {name_prefix}"
100 return str(value)
101
102
103def add_binary_prefix(value: float) -> str:

Callers

nothing calls this directly

Calls 2

get_positiveMethod · 0.80
get_negativeMethod · 0.80

Tested by

no test coverage detected