percent.go
percent.go - Overview
-
Overview This file defines a
percentFormatter
for formatting floating-point numbers as percentages. It includes functions to format values with and without multiplying by 100, appending a "%" symbol. -
Detailed Documentation
percentFormatter
- Purpose:
percentFormatter
is a struct that implements theFormatter
interface for formatting numbers as percentages. - Parameters: None
- Returns: None
NewPercentFormatter
- Purpose: Creates a new instance of
percentFormatter
. - Parameters: None
- Returns:
Formatter
: A pointer to a newpercentFormatter
instance.
(*percentFormatter) Name
- Purpose: Returns the name of the formatter, which is "percent".
- Parameters: None
- Returns:
string
: "percent"
toPercent
- Purpose: Formats a floating-point number to a percentage string with a specified number of decimal places, appending a "%" symbol.
- Parameters:
value
(float64
): The value to format.decimals
(DecimalCount
): The number of decimal places to include (currently unused).
- Returns:
string
: The formatted percentage string.
toPercentUnit
- Purpose: Multiplies a floating-point number by 100 and formats it to a percentage string with a specified number of decimal places, appending a "%" symbol.
- Parameters:
value
(float64
): The value to format.decimals
(DecimalCount
): The number of decimal places to include (currently unused).
- Returns:
string
: The formatted percentage string.
(f *percentFormatter) Format
- Purpose: Formats a floating-point number to a percentage string based on the specified unit.
- Parameters:
value
(float64
): The value to format.unit
(string
): The unit of the value. If the unit is "percent", the value is formatted as a percentage directly. If the unit is "percentunit", the value is multiplied by 100 before formatting as a percentage.
- Returns:
string
: The formatted percentage string. If the unit does not match "percent" or "percentunit", the function returns the value formatted as a string usingfmt.Sprintf
.
-
Code Examples N/A
-
Clarity and Accuracy The documentation reflects the code accurately without additional assumptions.
-
Markdown & MDX Perfection The markdown is valid and should not cause issues.
-
Edge Cases To Avoid Breaking MDX All potential MDX breaking characters are escaped or handled correctly.
-
Getting Started Relevance Include in Getting Started: NO