3

I'm trying to alter the existing number formatting in my company's application to make it more readable for international users. This is a stock trading application, so most stock prices come in with numbers precise to 2 decimal points, like so-> 17.23 We could also get ticks in that have precision out to 4 decimal points, so a penny stock might be 0.0341. The original string format that we were using for stocks was "#,##0.00##" Which would give us the format we wanted (essentially trimming '0's). The problem here is the ',' and '.' are forced onto the user, where in many other countries the thousands separator is '.' and the decimal point is ','. Boss man doesn't want to use "N4" for all numbers, even though this would resolve the globalization issue. Is it possible to have a globalized custom string format?

Other options besides writing some middle man code to internationalize numbers formatted the original way or another string.format method?

2 Answers 2

1

Check this out:

float value = 0.0341f;
string output = string.Empty;
CultureInfo brazil = new CultureInfo("pt-BR");
CultureInfo usa = new CultureInfo("en-US");
output = value.ToString("C4", brazil.NumberFormat); //output is R$ 0,0341
output = value.ToString("C4", usa.NumberFormat); //output is $0.0341
Sign up to request clarification or add additional context in comments.

Comments

0

The , and . in the custom format string already translate into the correct separators for the current culture. You should not need to change your code. See MSDN.

3 Comments

Ah, you're right. Apparently my problem was the thread generating the strings was not running as the culture I thought I specified.
The only other problem I see with this is Currency, if I wanted 2-4 decimal precision with the current culture's currency symbol in front if it, is there a nice way to do this? Using "$###,##0.00##" will always use the '$' since it isn't a placeholder for the culture's currency symbol (according to MSDN) correct?
look at my answer, just change N4 to C4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.