Click or drag to resize

CompactNumberType Class

Message formatting class for a numeric value. For the values below 1000 the resulted message is formatted so that it takes approximately 4 digits. Too small values will be padded with zeros after the dot.
Inheritance Hierarchy
SystemObject
  KSPDev.GUIUtils.TypeFormattersCompactNumberType

Namespace:  KSPDev.GUIUtils.TypeFormatters
Assembly:  KSPDev_Utils.2.0 (in KSPDev_Utils.2.0.dll) Version: 2.0 for KSP v1.8+
Syntax
C#
public sealed class CompactNumberType
Request Example View Source

The CompactNumberType type exposes the following members.

Constructors
  NameDescription
Public methodCode exampleCompactNumberType
Constructs an object from a numeric value.
Top
Methods
  NameDescription
Public methodStatic memberCode exampleFormat
Formats the value into a human friendly string.
Public methodToString
Returns a string formatted as a human friendly distance specification.
(Overrides ObjectToString.)
Top
Operators
Fields
  NameDescription
Public fieldvalue
A wrapped numeric value.
Top
Remarks

Use it as a generic parameter when creating a LocalizableMessage descendants.

Examples
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"
  }
}
Examples
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"
Examples
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"
See Also

Reference

KSPDev.GUIUtils.TypeFormattersCompactNumberType