Numbers
provide.foundation.formatting.numbers
¶
TODO: Add module docstring.
Functions¶
format_duration
¶
Format seconds as human-readable duration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seconds
|
float
|
Duration in seconds |
required |
short
|
bool
|
Use short format (1h30m vs 1 hour 30 minutes) |
False
|
Returns:
| Type | Description |
|---|---|
str
|
Human-readable duration string |
Examples:
>>> format_duration(90)
'1 minute 30 seconds'
>>> format_duration(90, short=True)
'1m30s'
>>> format_duration(3661)
'1 hour 1 minute 1 second'
>>> format_duration(3661, short=True)
'1h1m1s'
Source code in provide/foundation/formatting/numbers.py
format_number
¶
Format number with thousands separators.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num
|
float
|
Number to format |
required |
precision
|
int | None
|
Decimal places (None for automatic) |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted number string |
Examples:
Source code in provide/foundation/formatting/numbers.py
format_percentage
¶
Format value as percentage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
Value to format (0.5 = 50%) |
required |
precision
|
int
|
Decimal places |
1
|
include_sign
|
bool
|
Include + sign for positive values |
False
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted percentage string |
Examples:
>>> format_percentage(0.5)
'50.0%'
>>> format_percentage(0.1234, precision=2)
'12.34%'
>>> format_percentage(0.05, include_sign=True)
'+5.0%'
Source code in provide/foundation/formatting/numbers.py
format_size
¶
Format bytes as human-readable size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size_bytes
|
float
|
Size in bytes |
required |
precision
|
int
|
Decimal places for display |
1
|
Returns:
| Type | Description |
|---|---|
str
|
Human-readable size string |
Examples:
>>> format_size(1024)
'1.0 KB'
>>> format_size(1536)
'1.5 KB'
>>> format_size(1073741824)
'1.0 GB'
>>> format_size(0)
'0 B'