TryParse
decimal d = 0;
string s = "123.456";
if (decimal.TryParse(s, out d))
MessageBox.Show(d.ToString("N1"));
else
MessageBox.Show(s);
Excel 的 MROUND
/// <summary>
/// MROUND 函數為:傳回四捨五入為所需倍數的數字。EX.MROUND(7,5)=>5 MROUND(8,5)=>10
/// </summary>
/// <param name="number">原始數值</param>
/// <param name="multiple">倍數因子 (計算0.5的倍數就傳0.5)</param>
/// <returns>計算後的結果,效果等同 Excel MROUND 公式</returns>
public static decimal GetMROUND(decimal number, double multiple)
{
return Math.Round(number / (decimal)multiple, MidpointRounding.AwayFromZero) * (decimal)multiple;
}