Thursday, January 27, 2011

A beautiful C# logical

A TextBox in the web page(It will show decimal), data store in database(no decimal). if input nothing, I will give the value "999999" to the database, if the input value is "4.56", I will give the value "456" to the database.
when I get the value from the database, if the database value is "999999", the TextBox will display null; if the database value is "456", then the TextBox will display 4.56".
That is the function:

Code:


public static string TotalBaselineMaximum(string MaximumAMT)
{
string tmpMaximumAMT = "";

if (MaximumAMT == "")
tmpMaximumAMT = "999999";
else if (MaximumAMT == "999999" || MaximumAMT == "0")
tmpMaximumAMT = "";
else
{
decimal dec;
dec = Convert.ToDecimal(MaximumAMT);
if (MaximumAMT.Contains("."))
tmpMaximumAMT = Math.Round(dec * 100).ToString();
else
tmpMaximumAMT = (dec / 100).ToString();
}

return tmpMaximumAMT;
}

No comments:

Post a Comment