diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-03-24 14:56:11 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-03-24 14:56:11 -0400 |
| commit | 31af868b5d5825b3179ae8cdb85554f993e20344 (patch) | |
| tree | 87b80cd1ff577d1df0b86eaefca1e6106da6140b /docs | |
| parent | f79d6cc20a08711bc7d5fc2259c2f0bd5e0f744d (diff) | |
Add num:percent()
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/nums.md | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/docs/nums.md b/docs/nums.md index 7a86a585..02859d28 100644 --- a/docs/nums.md +++ b/docs/nums.md @@ -129,7 +129,7 @@ called either on the type itself: `Num.sqrt(x)` or as a method call: - [`func atanh(x: Num -> Num)`](#atanh) - [`func cbrt(x: Num -> Num)`](#cbrt) - [`func ceil(x: Num -> Num)`](#ceil) -- [`clamped(x, low, high: Num -> Num)`](#clamped) +- [`func clamped(x, low, high: Num -> Num)`](#clamped) - [`func copysign(x: Num, y: Num -> Num)`](#copysign) - [`func cos(x: Num -> Num)`](#cos) - [`func cosh(x: Num -> Num)`](#cosh) @@ -155,6 +155,7 @@ called either on the type itself: `Num.sqrt(x)` or as a method call: - [`func near(x: Num, y: Num, ratio: Num = 1e-9, min_epsilon: Num = 1e-9 -> Bool)`](#near) - [`func nextafter(x: Num, y: Num -> Num)`](#nextafter) - [`func parse(text: Text -> Num?)`](#parse) +- [`func percent(n: Num -> Text)`](#percent) - [`func rint(x: Num -> Num)`](#rint) - [`func round(x: Num -> Num)`](#round) - [`func scientific(n: Num, precision: Int = 0 -> Text)`](#scientific) @@ -922,6 +923,29 @@ as a number. --- +### `percent` +Convert a number into a percentage text with a percent sign. + +```tomo +func percent(n: Num, precision: Int = 0 -> Text) +``` + +- `n`: The number to be converted to a percent. +- `precision`: The number of decimal places. Default is `0`. + +**Returns:** +A text representation of the number as a percentage with a percent sign. + +**Example:** +```tomo +>> 0.5:percent() += "50%" +>> (1./3.):percent(2) += "33.33%" +``` + +--- + ### `rint` Rounds a number to the nearest integer, with ties rounded to the nearest even integer. |
