#import "@preview/wrap-it:0.1.0": wrap-content // https://github.com/ntjess/wrap-it/blob/main/docs/manual.pdf #import "./doc_templates/src/note.typ": * #import "./doc_templates/src/style.typ": set_style
#show: doc => set_style( topic: "scaler", author: "구FS", language: "EN", doc ) #set text(size: 3.5mm)
#align(center, text(size: 2em, weight: "bold")[scaler])
#line(length: 100%, stroke: 0.3mm)
= Introduction
This crate provides a convenient Formatter
to scale, round, and display numbers.
Scaling describes the usage of #link("https://en.wikipedia.org/wiki/Metric_prefix")[decimal] or #link("https://en.wikipedia.org/wiki/Binary_prefix")[binary unit prefixes] to increase readability; though no scaling and scientific notation are also supported.
Rounding can be done either to a specified magnitude or to a number of significant digits.
Separators can be freely adjusted. The group separator separates groups of digits every 3 digits before the decimal separator, while the decimal separator separates the integer and fractional parts of a number.
The sign behaviour can be set to always show the sign, only show the sign when the number is negative, or never show the sign.
= Table of Contents
#outline()
#pagebreak(weak: true)
= Usage
- Execute
Formatter::new
to create a newFormatter
with default settings. - Adjust separators, rounding, scaling, and sign behaviour as necessary using the setters.
- Format numbers with
Formatter::format
.
== Rounding
-
Magnitude
:- Round to digit at magnitude $10^m$.
- Contains $m$.
let f: Formatter = new .set_rounding; assert_eq!; assert_eq!; assert_eq!; let f: Formatter = new .set_rounding; assert_eq!; assert_eq!; assert_eq!; let f: Formatter = new .set_rounding; assert_eq!; assert_eq!; assert_eq!; let f: Formatter = new .set_rounding; assert_eq!; assert_eq!; assert_eq!; let f: Formatter = new .set_rounding; assert_eq!; assert_eq!; assert_eq!;
-
SignificantDigits
:- Round to $n$ significant numbers.
- Contains $n$.
let f: Formatter = new .set_rounding; assert_eq!; assert_eq!; assert_eq!; let f: Formatter = new .set_rounding; assert_eq!; assert_eq!; assert_eq!; let f: Formatter = new .set_rounding; assert_eq!; assert_eq!; assert_eq!; let f: Formatter = new .set_rounding; assert_eq!; assert_eq!; assert_eq!; let f: Formatter = new .set_rounding; assert_eq!; assert_eq!; assert_eq!; let f: Formatter = new .set_rounding; assert_eq!; assert_eq!; assert_eq!;
== Scaling
-
Binary
:- Scales by factor $2^(10) = 1.024$.
- If no prefix for that magnitude defined: Fallback to scientific notation.
- Contains whether or not to put space between number and unit prefix.
let f: Formatter = new .set_scaling; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; let f: Formatter = new .set_scaling; assert_eq!;
-
Decimal
:- Scales by factor $10^(3) = 1.000$.
- If no prefix for that magnitude defined: Fallback to scientific notation.
- Contains whether or not to put space between number and unit prefix.
let f: Formatter = new .set_scaling; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; let f: Formatter = new .set_scaling; assert_eq!;
-
None
:- no scaling
- no fallback to scientific notation
let f: Formatter = new .set_scaling; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!;
-
Scientific
:- always scientific notation
let f: Formatter = new .set_scaling; assert_eq!; assert_eq!; assert_eq!;
== Separators
group_separator
- Separates groups every 3 digits before the decimal separator.
decimal_separator
- Separates the integer and fractional parts of a number.
let f: Formatter = new
.set_scaling
.set_separators;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
let f: Formatter = new
.set_scaling
.set_separators;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
let f: Formatter = new
.set_scaling
.set_separators;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
== Sign
-
Always
- Always show sign, even when number is positive.
let f: Formatter = new .set_sign; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!;
-
OnlyMinus
- Only show sign when number is negative.
let f: Formatter = new .set_sign; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!;