Click or drag to resize

PressureTypeFormat 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.

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.

The base pressure unit in the game is kilopascal. I.e. value 1.0 in the game units is one kilopascal. Keep it in mind when passing the argument.

Examples
Debug.Log(PressureType.Format(0.051));
// Prints: "Pressure is: 0.051 kPa"
Debug.Log(PressureType.Format(0.45));
// Prints: "Pressure is: 0.45 kPa"
Debug.Log(PressureType.Format(95.45));
// Prints: "Pressure is: 95.5 kPa"
Debug.Log(PressureType.Format(120.45));
// Prints: "Pressure is: 121 kPa"
Debug.Log(PressureType.Format(9535.45));
// Prints: "Pressure is: 9,536 kPa"
Examples
Debug.Log(PressureType.Format(1234.5678, format: "0.0000"));
// Prints: "1234.5678 kPa"
Debug.Log(PressureType.Format(1234.5678, format: "0.00"));
// Prints: "1234.57 kPa"
Debug.Log(PressureType.Format(1234.5678, format: "#,##0.00"));
// Prints: "1,234.57 kPa"
See Also