Click or drag to resize

PercentFixedTypeFormat Method

Formats the value into a human friendly string with a unit specification.

Namespace:  KSPDev.GUIUtils.TypeFormatters
Assembly:  KSPDev_Utils.1.0 (in KSPDev_Utils.1.0.dll) Version: 1.0 for KSP v1.6+
Syntax
C#
public static string Format(
	double value,
	string format = null
)
Request Example View Source

Parameters

value
Type: SystemDouble
The numeric value to format.
format (Optional)
Type: SystemString
The specific float number format to use. If the format is not specified, then it's choosen basing on the value. Note, that the value is multiplied by 100.0 before formatting.

Return Value

Type: String
A formatted and localized string
Remarks
The method tries to keep the resulted string meaningful and as short as possible. For this reason the big values may be scaled down and/or rounded.
Examples
Debug.Log(PercentType.Format(0.004));
// Prints: "0.40%"
Debug.Log(PercentType.Format(0.0041));
// Prints: "0.41%"
Debug.Log(PercentType.Format(0.01));
// Prints: "1.0%"
Debug.Log(PercentType.Format(0.014));
// Prints: "1.4%"
Debug.Log(PercentType.Format(0.0145));
// Prints: "1.45%"
Debug.Log(PercentType.Format(0.01456));
// Prints: "1.46%"
Debug.Log(PercentType.Format(0.1));
// Prints: "10%"
Debug.Log(PercentType.Format(0.105));
// Prints: "11%"
Debug.Log(PercentType.Format(5.5));
// Prints: "550%"
Examples
Debug.Log(PercentType.Format(0.12345678, format: "0.0000"));
// Prints: "12.3457%"
Debug.Log(PercentType.Format(0.12345678, format: "0.00"));
// Prints: "12.35%"
See Also