I would like to ask how i should add the minus sign front of a decimal value.
i want the user to add e.g. 100 and behind the s开发者_C百科cenes to convert it in -100
thank you.
What's wrong with
a = -a?
If it's a decimal, convert it to a decimal, and then multiple by literal -1m
. Or what Pavel said.
Multiply by -1.
I'm not sure about whether I got your question right. Are you asking how to negate a number?
decimal negated = -1.0M * userInputValue;
Is that what you are asking for? Or are you asking for automatically formatting the number as if the user had entered a negative number? In that case you could do:
string display = String.Format("-{0}", userInputValue);
I'm still not sure whether I get what you want...
精彩评论