Click here to Skip to main content
15,880,651 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
So if for example i enter 20 and execute the command instead of making it -20 it makes it 20-, why??

What I have tried:

textBox1.Text = (Double.Parse(textBox1.Text) * -1).ToString();
Posted
Updated 29-Jul-18 13:42pm
Comments
Kornfeld Eliyahu Peter 29-Jul-18 5:12am    
It probably around displaying RTL and LTR... nothing wrong with the value...

I just tried your code and it works fine. There must be something else in your program that is affecting your results. Or it may be that the regional settings on your system use a trailing minus sign for negative numbers.
 
Share this answer
 

It looks like System.Globalization.NumberStyles is set to AllowTrailingSign. You can change your double.Parse method to place the sign in front of the number like this.

C#
 string res=String.Format("{0:#.##;-#.##}", (Double.Parse("200.549") * -1));
//'-200.55'

The first 3 '#'symbols format a positive number. No '+' sign rounded to 2 decimal places. The second set of 3 '#'symbols format a negative number. A '-' sign followed by the number rounded to 2 decimal places.

 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900