Negative sign appears after number

In the enclosed file the display of all negative numbers occurs with the negative sign appearing after the number. Why is that the default. For example, instead of displaying -52%, this number is displayed as 52%-. The code to display is:

PercentCostVariance.Text = FormatPercent((ActualCosts - OriginalCosts) / OriginalCosts, 1)

I have checked my default window settings for Negative number format: -1.1
SignAppearsAfterNumber.PNG
labtracAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SStoryCommented:
Sounds like it may be using regional settings---where the - comes after

See this page:

http://msdn.microsoft.com/en-us/library/8zh1kxd7%28VS.80%29.aspx
0
gkfordCommented:
You can also force the format so that the display is consistent for all users thoughout your deployment and not dependent on any windows settings:
PercentCostVariance.Text = FormatPercent((ActualCosts - OriginalCosts) / OriginalCosts, 1).ToString("-%0.00")
The format here also forces 2 decimal places for precision.
 
0
labtracAuthor Commented:
When I tried the solution,

PercentCostVariance.Text = FormatPercent((ActualCosts - OriginalCosts) / OriginalCosts, 1).ToString("-%0.00")

 I got the following runtime error: InvalidCastException

Unable to cast object of type 'System.String' to type 'System.IFormatProvider'.
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

labtracAuthor Commented:
The only solution I found was the following, but this solution is not acceptable as it puts parentheses around the negative number and I want a - sign:

PercentCostVariance.Text = FormatPercent((ActualCosts - OriginalCosts) / OriginalCosts, NumDigitsAfterDecimal:=1, UseParensForNegativeNumbers:=True)
0
labtracAuthor Commented:
I figured out what is going on here. There is a right to left property for this field. When set to No it displays the number correctly as -28.7%, but left justified in the textbox. I was trying to get it displayed right justified in the textbox and I thought that setting the right to left property to Yes would do that. It does, but has the unintended consequence of putting the - sign after the % sign. So now I need another way of right justified the text in a texbox
0
gkfordCommented:
If it is a standard windows forms textbox, you should be able to use the TextAlign property.
(sorry for my earlier submission that steered you in the wrong direction - I should have tested it before posting.)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
labtracAuthor Commented:
Thanks that works. I also have a ListBox. There does not appear to be a way to apply this property to this type of object.
0
gkfordCommented:
There isn't any native justification in a listbox - what I've had to do in the past is set the font to a fixed font (courier new or lucida console or some other such font) and then use padleft so that everything aligns to the right.
ListBox1.Items.Add("1234".PadLeft(10))
ListBox1.Items.Add("56".PadLeft(10))
With a fixed font, the 6 will line up under the 4.
Hope this helps.
0
labtracAuthor Commented:
Thanks, ugly solution, but it works! Wish there was a way to not have to change the font.
0
gkfordCommented:
I agree - if anyone else has another solution, please post it because I'd like to see it.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.