Is this total you have in a numeric variable (e.g. int, double, short etc) If it is, you can use the System.Math.Abs() function as this will return the absolute value of whatever number is passed to it. For example: Double test =
-200.97; Double nonNegTest
= System.Math.Abs(test);
The message boxes above are for illustration only so that it can be seen what the effects of System.Math.Abs() are.
However, if your total is stored in a string variable or the like, you can convert the value to something numeric (using one of the Convert.ToXXX() functions) then use System.Math.Abs() and then place the non-negative result inside your original variable (using something like the ToString() function). For example: string
test = "-200"; int
conversionOfTest = Convert.ToInt32(test); int
nonNegVersionOfTest = System.Math.Abs(conversionOfTest);
You could streamline the above a lot more but for an example I think it will do. Once again, the message boxes are just for illustration of what has happened.
change negative sign
AvalonNewbie
Even simpler, just tack on a negative sign:
x = - x;
mikeret
now i have another case..
i have a positive value which i want to conver to negative
Amnu cherian
Genetic1234
Is this total you have in a numeric variable (e.g. int, double, short etc) If it is, you can use the System.Math.Abs() function as this will return the absolute value of whatever number is passed to it. For example:
Double test = -200.97;
Double nonNegTest = System.Math.Abs(test);
MessageBox.Show("Original: " + test.ToString());
The message boxes above are for illustration only so that it can be seen what the effects of System.Math.Abs() are.MessageBox.Show("Alteration: " + nonNegTest.ToString());
However, if your total is stored in a string variable or the like, you can convert the value to something numeric (using one of the Convert.ToXXX() functions) then use System.Math.Abs() and then place the non-negative result inside your original variable (using something like the ToString() function). For example:
string test = "-200";
int conversionOfTest = Convert.ToInt32(test);
int nonNegVersionOfTest = System.Math.Abs(conversionOfTest);
MessageBox.Show("Original: " + test);
You could streamline the above a lot more but for an example I think it will do. Once again, the message boxes are just for illustration of what has happened.test = nonNegVersionOfTest.ToString();
MessageBox.Show("Modified: " + test);
Hope that helps a bit.