sci
Builtin index · Collections & strings
result = sci(x, [digits=3], [style="unicode"])
Input: x, digits, style · Output: result
What it is
x is a number; digits (a whole number 1 to 20, default 3) counts significant digits; style is "unicode" (1.23 × 10⁻⁴⁵, for plot titles and labels), "tex" (1.23 \times 10^{-45}, for LaTeX/MathJax) or "ascii" (1.23 x 10^-45), or "math" ($1.23\times10^{-45}$: the $...$ math markup, which plots render as a raised exponent in SVG and PDF and hand to LaTeX as real math in TikZ -- the best choice for any title or label that may be exported to TikZ/LaTeX).
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = sci(x, [digits=3], [style="unicode"]) | x numberx is a number.digits number, optional (default 3)digits (a whole number 1 to 20, default 3) counts significant digits.style optional (default "unicode")style is "unicode" (1.23 × 10⁻⁴⁵, for plot titles and labels), "tex" (1.23 \times 10^{-45}, for LaTeX/MathJax) or "ascii" (1.23 x 10^-45), or "math" ($1.23\times10^{-45}$: the $...$ math markup, which plots render as a raised exponent in SVG and PDF and hand to LaTeX as real math in TikZ -- the best choice for any title or label that may be exported to TikZ/LaTeX). | result Str or string | Returns a Str. A value whose exponent is 0 prints as the bare mantissa (1.50), and a value that rounds up into the next power of ten carries into the exponent (9.999e4 at 2 digits is 1.0 × 10⁵, never 10.0 × 10⁴). NaN and Inf print as such. The same notation is available inside strings as "{x:.2sci}" and "{x:.2tex}". |
Examples
No documentation example calls this form yet. The Collections & strings chapter is where one belongs.
How it works
Scientific notation and printf-style formatting (numfmt_ops.rs): sci(x, [digits=3], [style=]) -> "1.23 × 10⁻⁴⁵", sprintf(fmt, ...) -> string, printf(fmt, ...) -> printed with no newline added.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.