Skip to main content

Module clients.convert.quantity_convertor

Functions​

number_str_to_quantity ​

def number_str_to_quantity(number_str: str) ‑> str

Helper function to call number_to_quantity() function with a string type argument.

number_to_quantity ​

def number_to_quantity(num: int) ‑> str

Convert number to string quantity. The highest suffix possible will be applied. If no suffix can be applied, return the same number without suffix.

Args​
num
integer number
Returns​

string quantity equivalent to the number

Examples​

1000 -> "1k" 1024 -> "1Ki" 1000000 -> "1M" 1048576 -> "1Mi" 2000 -> "2k" 2001 -> "2001" 2048 -> "2Ki" 2049 -> "2049"

optional_quantity_to_number_str ​

def optional_quantity_to_number_str(quantity: Optional[str]) ‑> Optional[str]

quantity_to_number ​

def quantity_to_number(quantity: str) ‑> int

Convert string quantity into number by applying the potential suffix. [quantity] = [number][suffix] [suffix] = [binarySI] | [decimalSI] [binarySI] = Ki | Mi | Gi | Ti | Pi [decimalSI] = k | M | G | T | P

Args​
quantity
string representation of a number with optional suffix.
Returns​

number equivalent to the quantity without suffix.

Raises​
ValueError
Invalid quantity value passed.
Examples​
  • "1k" -> 1000
  • "1Ki" -> 1024
  • "1M" -> 1000000
  • "1Mi" -> 1048576

quantity_to_number_str ​

def quantity_to_number_str(quantity: str) ‑> str

Helper function to convert return value of quantity_to_number() to string representation.


Feedback