开发者

Best way to add the minus "-" front of decimal value

开发者 https://www.devze.com 2023-01-01 11:13 出处:网络
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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消