NumberFormat

References
public sealed class NumberFormat : IStorable
Immutable collection of number formatting properties.

Constructors

NumberFormat

#
public NumberFormat(bool specialCaseIntegers, bool specialCaseRationals, bool specialCaseIntegralConstants, bool specialCaseRationalConstants, bool specialCaseIntegralRoots, int minimumDecimals, int maximumDecimals, bool roundLastDecimal, int mantissaMinimumDecimals, int mantissaMaximumDecimals, int eNotationLowerLimit, int eNotationUpperLimit, bool eNotationSuperscript)
Create a new NumberFormat state.
specialCaseIntegers (bool)If true, numbers that are close to integers are formatted as such.
specialCaseRationals (bool)If true, numbers that are close to rationals (ie. fractions) are formatted as such.
specialCaseIntegralConstants (bool)If true, number that are multiples of pi are formatted as such.
specialCaseRationalConstants (bool)If true, numbers that are some fraction of pi are formatted as such.
specialCaseIntegralRoots (bool)If true, numbers that are roots of integers are formatted as such.
minimumDecimals (int)Number of decimal places to always include during regular number formatting.
maximumDecimals (int)Maximum number of decimals to display during regular number formatting.
roundLastDecimal (bool)If true, excess decimals are rounded away silently. If false, they are still rounded but an ellipsis is appended to mark the loss.
mantissaMinimumDecimals (int)Number of decimals to always include during scientific notation formatting.
mantissaMaximumDecimals (int)Maximum number of decimals to display during scientific notation formatting.
eNotationLowerLimit (int)Numbers smaller than 10^limit will be displayed using scientific notation.
eNotationUpperLimit (int)Numbers bigger than 10^limit will be displayed using scientific notation.
eNotationSuperscript (bool)If true, scientific notation uses superscript symbols for the power.

Properties

DecimalFormat

#
public string DecimalFormat { get; }
Gets the formatting string for regular (decimal) notation.

Honest

#
public static NumberFormat Honest { get; }
Same as Minimal, but whenever the displayed digits do not capture the exact value, an ellipsis is appended.

Intent

#
public static NumberFormat Intent { get; }
Gets the standard humanistic number formatting for Grasshopper. The numeric format attempts to reverse engineer all intent.

MantissaMaximumDecimals

#
public int MantissaMaximumDecimals { get; }
Maximum number of decimals to display for the mantissa during scientific formatting.

MantissaMinimumDecimals

#
public int MantissaMinimumDecimals { get; }
Minimum number of decimals to display for the mantissa during scientific formatting.

MaximumDecimals

#
public int MaximumDecimals { get; }
Maximum number of decimals to display.

Minimal

#
public static NumberFormat Minimal { get; }
Gets the number formatting rules which most closely track common formatting in software. Floating point numbers always have at least one decimal digit, but no more than 6 and the final digit is rounded.

MinimumDecimals

#
public int MinimumDecimals { get; }
Minimum number of decimals to display.

RoundLastDecimal

#
public bool RoundLastDecimal { get; }
Round away excess decimals silently. If false, excess decimals are still rounded, but an ellipsis character will be appended to mark the loss.

ScientificFormat

#
public string ScientificFormat { get; }
Gets the formatting string for scientific notation.

ScientificNotationLowerThreshold

#
public int ScientificNotationLowerThreshold { get; }
Gets the power of ten below which numbers are formatted using scientific notation.

ScientificNotationSuperscript

#
public bool ScientificNotationSuperscript { get; }
Gets whether to format scientific notation using 'e' or using superscripts. If this property yields false, the formatting should look like 1.534e-17, if this property yields true, the formatting should look like 1.534×10⁻¹⁷.

ScientificNotationUpperThreshold

#
public int ScientificNotationUpperThreshold { get; }
Gets the power of ten above which numbers are formatted using scientific notation.

SpecialCaseIntegers

#
public bool SpecialCaseIntegers { get; }
Numbers close to integers will be displayed as such.

SpecialCaseIntegralConstants

#
public bool SpecialCaseIntegralConstants { get; }
Numbers that are close to multiples of PI will be displayed as such.

SpecialCaseIntegralRoots

#
public bool SpecialCaseIntegralRoots { get; }
Numbers that are close to integer roots will be displayed as such.

SpecialCaseRationalConstants

#
public bool SpecialCaseRationalConstants { get; }
Numbers that are close to fractional values of PI will be displayed as such.

SpecialCaseRationals

#
public bool SpecialCaseRationals { get; }
Numbers that are close to fractions will be displayed as such.

Methods

Format

#
public string Format(BigInteger value)
Format an integer value.
value (BigInteger)

Format

#
public string Format(double value)
Format a floating point value.
value (double)

Format

#
public string Format(int value)
Format an integer value.
value (int)

Format

#
public string Format(long value)
Format an integer value.
value (long)

Format

#
public string Format(string pattern, Font font, float maximum, params double[] numbers)
Format a list of numbers until they fit within the provided limit. This method will iteratively lower the MaximumDecimals to 1 until the text fits within the limit, or it will return the shortest string.
pattern (string)Pattern containing appropriate placeholders {0}, {1}, etc. for all values.
font (Font)Font for measuring.
maximum (float)Maximum allowed width of string.
numbers (params double[])Numbers to insert.
Formatted string.

Format

#
public string Format(string pattern, params double[] numbers)
Format a list of numbers using a formatting pattern.
pattern (string)Pattern containing appropriate placeholders {0}, {1}, etc. for all values.
numbers (params double[])Numbers to insert.
Formatted string.

Modify

#
public NumberFormat Modify(bool? specialCaseIntegers = null, bool? specialCaseRationals = null, bool? specialCaseIntegralConstants = null, bool? specialCaseRationalConstants = null, bool? specialCaseIntegralRoots = null, int? minimumDecimals = null, int? maximumDecimals = null, bool? roundLastDecimal = null, int? mantissaMinimumDecimals = null, int? mantissaMaximumDecimals = null, int? eNotationUpperLimit = null, int? eNotationLowerLimit = null, bool? eNotationSuperscript = null)
Modify this formatting.
specialCaseIntegers (bool? = null)
specialCaseRationals (bool? = null)
specialCaseIntegralConstants (bool? = null)
specialCaseRationalConstants (bool? = null)
specialCaseIntegralRoots (bool? = null)
minimumDecimals (int? = null)
maximumDecimals (int? = null)
roundLastDecimal (bool? = null)
mantissaMinimumDecimals (int? = null)
mantissaMaximumDecimals (int? = null)
eNotationUpperLimit (int? = null)
eNotationLowerLimit (int? = null)
eNotationSuperscript (bool? = null)

Store

#
public void Store(IWriter writer)
Serializer.
writer (IWriter)Writer object.
Store

WithoutRounding

#
public NumberFormat WithoutRounding()
Disable the RoundLastDecimal property.

WithRounding

#
public NumberFormat WithRounding()
Enable the RoundLastDecimal property.