svg_path/number_format
Shared numeric formatting helpers.
This module keeps decimal rounding, fixed decimal formatting, and left-padding behavior consistent across structural inspection and SVG path serialization. Higher-level modules still decide which numbers should be included in the lookahead list for automatic padding.
Types
Formatting for digits to the left of the decimal point.
pub type LeftDecimalOptions {
Succinct
AutoLeftPadding
LeftPadding(Int)
}
Constructors
-
SuccinctDo not pad numbers on the left.
-
AutoLeftPaddingPre-scan the formatted value and choose the smallest shared left width that aligns its numbers.
-
LeftPadding(Int)Pad numbers to the given left width.
The width includes a leading minus sign for negative numbers.
A prepared numeric formatter.
pub opaque type NumberFormat
Options for numeric formatting.
pub type Options {
Options(
left_decimals: LeftDecimalOptions,
right_decimals: RightDecimalOptions,
)
}
Constructors
-
Options( left_decimals: LeftDecimalOptions, right_decimals: RightDecimalOptions, )Arguments
- left_decimals
-
Formatting for digits to the left of the decimal point.
- right_decimals
-
Formatting for digits to the right of the decimal point.
Formatting for digits to the right of the decimal point.
pub type RightDecimalOptions {
System
AtMost(Int)
Fixed(Int)
}
Constructors
-
SystemUse the system float formatter, stripped of purely trailing decimal zeroes.
-
AtMost(Int)Use at most this many decimal places, stripping trailing zeroes.
-
Fixed(Int)Use exactly this many decimal places.
Values
pub fn code_number(
value: Float,
with format: NumberFormat,
) -> String
Format a number for copy-pasteable Gleam code.
Whole numbers are given an explicit .0 suffix before left-padding is
applied.
pub fn prepare(
options: Options,
numbers: List(Float),
) -> NumberFormat
Prepare a formatter, using the supplied numbers to choose automatic padding.
pub fn raw_number(number: Float, options: Options) -> String
Format a number without applying left-padding.
This is useful when deciding which compact SVG command form a number would use before padding is added.