tags:

views:

75

answers:

4

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 scenes to convert it in -100

thank you.

+4  A: 

What's wrong with

a = -a?

Pavel Radzivilovsky
Maybe do this in an `if (a > 0)` block?
Moron
i just parse it "-" + value
AlwaysBeCoding
@always do you do arithmetics thru text? :)
Pavel Radzivilovsky
+1  A: 

If it's a decimal, convert it to a decimal, and then multiple by literal -1m. Or what Pavel said.

David M
A: 

Multiply by -1.

Breander
A: 

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...

Thorsten Dittmar