static void ctrl_TextChanged(object sender, EventArgs e) { TextBox t = (TextBox)sender; decimal money = CurrencyUtility.ToDecimal(t.Text); t.Text = CurrencyUtility.DecimalToString(money); t.SelectionStart = t.TextLength; }
private static object ChangeType(object obj, Type t) { try { if (string.IsNullOrWhiteSpace(obj.ToString())) { if (t == typeof(int)) { return((int)(0)); } if (t == typeof(double)) { return((double)(0)); } if (t == typeof(decimal)) { return((decimal)(0)); } if (t == typeof(float)) { return((float)(0)); } } if ((t == typeof(decimal) || t == typeof(Decimal))) { return(CurrencyUtility.ToDecimal(obj.ToString())); } if (t == typeof(Guid) && !string.IsNullOrWhiteSpace(obj.ToString())) { return(Guid.Parse(obj.ToString())); } return(Convert.ChangeType(obj, t)); } catch { obj = ""; return(ChangeType(obj, t)); } }
public static decimal PercentToMoney(double percent, string money) { decimal temp = CurrencyUtility.ToDecimal(money); return((decimal)percent * temp); }