Click or drag to resize

CostType Class

Localized message formatting class for a numeric value that represents a cost.
Inheritance Hierarchy
SystemObject
  KSPDev.GUIUtils.TypeFormattersCostType

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 CostType
Request Example View Source

The CostType type exposes the following members.

Constructors
  NameDescription
Public methodCode exampleCostType
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 volume specification.
(Overrides ObjectToString.)
Top
Operators
Fields
  NameDescription
Public fieldStatic memberFundPrefix
The prefix to use to denote the "money" cost values.
Public fieldvalue
A wrapped numeric value.
Top
Remarks

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

Examples
public class CostTypeDemo1 : PartModule {
  static readonly Message<CostType> msg1 = new Message<CostType>(
      "#TypeDemo_msg1", defaultTemplate: "Cost is: <<1>>");

  void Show() {
    Debug.Log(msg1.Format(0.4));
    // Prints: "Cost is: √ 0.40"
    Debug.Log(msg1.Format(0.41));
    // Prints: "Cost is: √ 0.41"
    Debug.Log(msg1.Format(1.0));
    // Prints: "Cost is: √ 1.00"
    Debug.Log(msg1.Format(1.41));
    // Prints: "Cost is: √ 1.41"
    Debug.Log(msg1.Format(1234.555));
    // Prints: "Cost is: √ 1,234.56"
  }
}
Examples
Debug.Log(CostType.Format(0.4));
// Prints: "Cost is: √ 0.40"
Debug.Log(CostType.Format(0.41));
// Prints: "Cost is: √ 0.41"
Debug.Log(CostType.Format(1.0));
// Prints: "Cost is: √ 1.00"
Debug.Log(CostType.Format(1.41));
// Prints: "Cost is: √ 1.41"
Debug.Log(CostType.Format(1234.555));
// Prints: "Cost is: √ 1,234.56"
Examples
Debug.Log(CostType.Format(1234.5678, format: "0.0000"));
// Prints: "√ 1234.5678"
Debug.Log(CostType.Format(1234.5678, format: "#,##0.00"));
// Prints: "√ 1,234.57"
See Also

Reference

KSPDev.GUIUtils.TypeFormattersCostType