Showing posts with label iformatprovider. Show all posts
Showing posts with label iformatprovider. Show all posts

Monday, March 26, 2012

string.ToString (IFormatProvider) doesnt take case of the provider ?

It's seem like a bug in the framework... but I'm not sure...
It's must seems weird, but I have a string variable and I want to apply a format and get the string formatted in that format. My original string is a numeric value and I want to obtain a string formatted based on the culture of the current thread.
string numericValue = "1234.56";
string returnValue = numericValue.ToString (System.Globalization.NumberFormatInfo.CurrentInfo);
But, it doesn't work. So, I check the code in the framework and there two methods ToString on the string Object. And both, return the this even the one with the provider parameter.

publicstringToString(IFormatProvider provider){returnthis;}
I you agree with me that there is a bug in the framework ?

hello.
i think that you're seeing it the wrong way.
what you want to do is get your number (ex.: double) and use the ToString method of that struct.
Double num = ...;
num.ToString( provider );
i think that using tostring with a provider on a string doesn't make any sense...

What I am trying to do is converting the format of a string from one culture to another. Say that you have a string 1 234,56 on the french-Canada culture and want to format the string to the english-US culture. I can parse the string to double and returning back to string. But I see that the string class have a method ToString who take a FormatProvider and do nothing with the parameter.


hello.

what i was trying to say is that if you're supposed to have a number, then use a variable of the desired type to keep it and parse it to the desired culture.


My simple solution is:
private void Form1_Load(object sender, EventArgs e)
{
double i = 1234.56;
textBox1.Text = i.ToString("0,000.00");

}

StringBuilder AppendFormart cannot handle String!

Hello,

If I use AppendFormat with string as a parameter.
I get string cannot be converted to IFormatProvider.

This occurs in 2.0

Thanks.
JayIt might be the actual format that's invalid, not the parameter. Perhaps an
example of code that doesn't work would help...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/

"Jay Balapa" <jbalapa@.hotmail.com> wrote in message
news:eZplPbsGGHA.1100@.TK2MSFTNGP10.phx.gbl...
> Hello,
> If I use AppendFormat with string as a parameter.
> I get string cannot be converted to IFormatProvider.
> This occurs in 2.0
> Thanks.
> Jay

StringBuilder AppendFormart cannot handle String!

Hello,
If I use AppendFormat with string as a parameter.
I get string cannot be converted to IFormatProvider.
This occurs in 2.0
Thanks.
JayIt might be the actual format that's invalid, not the parameter. Perhaps an
example of code that doesn't work would help...
Karl
MY ASP.Net tutorials
http://www.openmymind.net/
"Jay Balapa" <jbalapa@.hotmail.com> wrote in message
news:eZplPbsGGHA.1100@.TK2MSFTNGP10.phx.gbl...
> Hello,
> If I use AppendFormat with string as a parameter.
> I get string cannot be converted to IFormatProvider.
> This occurs in 2.0
> Thanks.
> Jay
>