DistanceTypeFormat Method |
Namespace: KSPDev.GUIUtils.TypeFormatters
public static string Format( double value, Nullable<double> scale = null, string format = null )
The unknown scales will be rounded down to the closest known scale. If this parameter is omitted, then the best scale for the value will be choosen automatically.
Debug.Log(DistanceType.Format(0.051)); // Prints: "0.051 m" Debug.Log(DistanceType.Format(0.45)); // Prints: "0.45 m" Debug.Log(DistanceType.Format(95.45)); // Prints: "95.5 m" Debug.Log(DistanceType.Format(120.45)); // Prints: "121 m" Debug.Log(DistanceType.Format(9535.45)); // Prints: "9536 m" Debug.Log(DistanceType.Format(12345.45)); // Prints: "12.5 km" Debug.Log(DistanceType.Format(123456.45)); // Prints: "123457 km"
Debug.Log(DistanceType.Format(123456.56, scale: 1000)); // Prints: "123.6 km" Debug.Log(DistanceType.Format(123456.56, scale: 1)); // Prints: "123456.6 m" Debug.Log(DistanceType.Format(123456.56, scale: 10)); // Scale 10 is not known, so it's rounded down to 1. // Prints: "123456.6 m" Debug.Log(DistanceType.Format(123.56, scale: 1000)); // Prints: "0.1 km"
Debug.Log(DistanceType.Format(1234.5678, format: "0.0000")); // Prints: "1234.5678 m" Debug.Log(DistanceType.Format(1234.5678, format: "0.00")); // Prints: "1234.57 m" Debug.Log(DistanceType.Format(1234.5678, format: "0.0000", scale: 1000)); // Prints: "1.2346 km" Debug.Log(DistanceType.Format(1234.5678, format: "0.00", scale: 1000)); // Prints: "1.24 km"