I have a question. In my case I want to retrieve the last digit of a decimal value in order to do rounding adjustment. Following is my code:
private void calculateADJ()
{
string result = Strings.Right(txtGTotal.Text, 1);
if (result == "1" || result == "6")
{
txtStoreRA.Text = "-0.01";
txtOutstanding.Text = (Convert.ToDouble(txtGTotal.Text) - 0.01).ToString("0.00");
}
if (result == "2" || result == "7")
{
txtStoreRA.Text = "-0.02";
txtOutstanding.Text = (Convert.ToDouble(txtGTotal.Text) - 0.02).ToString("0.00");
}
if (result == "3" || result == "8")
{
txtStoreRA.Text = "0.01";
txtOutstanding.Text = (Convert.ToDouble(txtGTotal.Text) + 0.01).ToString("0.00");
}
if (result == "4" || result == "9")
{
txtStoreRA.Text = "0.02";
txtOutstanding.Text = (Convert.ToDouble(txtGTotal.Text) + 0.02).ToString("0.00");
}
else
{
txtOutstanding.Text = txtGTotal.Text;
}
}
For example, if the number is 11.93, it will convert it into 11.95. Any suggestion or help will be much appreciate. For your information, I'm doing this with pocket PC emulator 2003 in Visual studio 2005.
My problem is that the value didn't change as I expected.
When I run my program, for example the txtGTotal.Text = 11.94, so my txtOutStanding.Text should be 11.95. However, txtOutStanding.Text still 11.94.
Not sure who is the one who devoting, at least you can provide me the explanation. Getting devote without a reason feels suck, a reason will at least can be a improvement for next time before asking a question. Thank you
I would say Ian's answer is much clearer than the answer provided at the post that I duplicate.