The web application I'm working on (another author wrote it) has a decimal variable that resets two zeros after the decimal. It does not discard the final 2 digits if they contain a number> 0 or a combination. The value is derived from a text file.
Example text value: 261.00
Example of a decimal variable (TotalDue): 261
During debugging, when you hover over “TotalDue” (in the example below), the value is displayed as 261, and when I expand the debugger, it reads “261M”:
decimal TotalDue = Convert.ToDecimal(InputRow.Substring(260, 12));
I tried to cast it as a string (but initially it still reads as “261” instead of 261.00) and then converts it in various ways as follows. Nothing works!
string TotalDue = InputRow.Substring(260, 12); strTotalDue = String.Format("{0:F2}", TotalDue); strTotalDue = String.Format("{0:N2}", TotalDue); strTotalDue = String.Format(TotalDue, "0.00"); strTotalDue = TotalDue.ToString("G29"); strTotalDue = String.Format("{0:0.00}", TotalDue); strTotalDue = TotalDue.ToString("N2");
What am I missing? Does it matter where the text file came from? It started in the Access database.
UPDATE: Today (12/1/15). I realized that I never noted the answer, because in the end I refused the source code and rewrote it in C # .net. I will mark Cole Campbell's correct answer because his remarks ("build the decimal code in such a way as to provide him with sufficient data about the accuracy of the input") prompted me to come up with a solution that I made to manipulate the incoming data. I did this in the method - only showing the part that matters (AmtDue) below. A reminder that the incoming data was in the format "261.00" (for example, AmtDue = 261.00):
string AmtDue = Convert.ToString(AmountDue).Replace(".", ""); string finalstring = ("0000000000" + AmtDue).Substring(AmtDue.Length);