CompactNumberType Class |
Namespace: KSPDev.GUIUtils.TypeFormatters
The CompactNumberType type exposes the following members.
Name | Description | |
---|---|---|
CompactNumberType | Constructs an object from a numeric value. |
Name | Description | |
---|---|---|
Format | Formats the value into a human friendly string. | |
ToString | Returns a string formatted as a human friendly distance specification. (Overrides ObjectToString.) |
Name | Description | |
---|---|---|
(Double to CompactNumberType) | Converts a numeric value into a type object. | |
(CompactNumberType to Double) | Converts a type object into a numeric value. |
Use it as a generic parameter when creating a LocalizableMessage descendants.
public class CompactNumberType1 : PartModule { static readonly Message<CompactNumberType> msg1 = new Message<CompactNumberType>( "#TypeDemo_msg1", defaultTemplate: "Value is: <<1>>"); void Show() { Debug.Log(msg1.Format(0.051)); // Prints: "Value is: 0.051" Debug.Log(msg1.Format(0.45)); // Prints: "Value is: 0.45" Debug.Log(msg1.Format(95.45)); // Prints: "Value is: 95.5" Debug.Log(msg1.Format(120.45)); // Prints: "Value is: 121" Debug.Log(msg1.Format(9535.45)); // Prints: "Value is: 9,536" } }
Debug.Log(CompactNumberType.Format(0.051)); // Prints: "Value is: 0.051" Debug.Log(CompactNumberType.Format(0.45)); // Prints: "Value is: 0.45" Debug.Log(CompactNumberType.Format(95.45)); // Prints: "Value is: 95.5" Debug.Log(CompactNumberType.Format(120.45)); // Prints: "Value is: 121" Debug.Log(CompactNumberType.Format(9535.45)); // Prints: "Value is: 9,536"
Debug.Log(DistanceType.Format(1234.5678, format: "0.0000")); // Prints: "1234.5678" Debug.Log(DistanceType.Format(1234.5678, format: "0.00")); // Prints: "1234.57" Debug.Log(DistanceType.Format(1234.5678, format: "#,##0.00")); // Prints: "1,234.57"