public void NumericUtility_TryParseDecimal_1() { decimal value; Assert.IsTrue(NumericUtility.TryParseDecimal("1.23", out value)); Assert.AreEqual(1.23m, value); Assert.IsFalse(NumericUtility.TryParseDecimal("hello", out value)); Assert.IsFalse(NumericUtility.TryParseDecimal(string.Empty, out value)); Assert.IsFalse(NumericUtility.TryParseDecimal(null, out value)); }
/// <summary> /// Get decimal value from application configuration. /// </summary> public static decimal GetDecimal ( [NotNull] string key, decimal defaultValue = 0.0m ) { string setting = CM.AppSettings[key]; if (!NumericUtility.TryParseDecimal(setting, out decimal result)) { result = defaultValue; } return(result); }
/// <summary> /// Get decimal value from application configuration. /// </summary> public static decimal GetDecimal ( [NotNull] string key, decimal defaultValue ) { #if DROID || ANDROID || UAP return(defaultValue); #else decimal result; string s = CM.AppSettings[key]; if (!NumericUtility.TryParseDecimal(s, out result)) { result = defaultValue; } return(result); #endif }