public void NumericUtility_TryParseFloat_1() { float value; Assert.IsTrue(NumericUtility.TryParseFloat("1.23", out value)); Assert.AreEqual(1.23f, value); Assert.IsTrue(NumericUtility.TryParseFloat("1,23", out value)); Assert.AreEqual(1.23f, value); Assert.IsFalse(NumericUtility.TryParseFloat("hello", out value)); Assert.IsFalse(NumericUtility.TryParseFloat(string.Empty, out value)); Assert.IsFalse(NumericUtility.TryParseFloat(null, out value)); }
/// <summary> /// Get single-precision float value from application configuration. /// </summary> public static float GetSingle ( [NotNull] string key, float defaultValue = 0.0f ) { string setting = CM.AppSettings[key]; if (!NumericUtility.TryParseFloat(setting, out float result)) { result = defaultValue; } return(result); }
/// <summary> /// Get single-precision float value from application configuration. /// </summary> public static float GetSingle ( [NotNull] string key, float defaultValue ) { #if DROID || ANDROID || UAP return(defaultValue); #else float result; string s = CM.AppSettings[key]; if (!NumericUtility.TryParseFloat(s, out result)) { result = defaultValue; } return(result); #endif }