dynamic formatting using string.format

Hi,

I have a different scenario in formatting string.

The format value and format type are in database.

So the code needs to format the value accordingly.

Say, if it is currency value it has to the currency format.

If it is number value it has to the number format.

Here I have given the sample code.

string strValue= "1234567";

string strFormat="{0:c}";

System.Console.WriteLine(string.Format(strFormat,strValue));

System.Console.ReadLine();

But the above code does not formatting...

I hope you have solution for this.

thanks in advance

chandra babu

[837 byte] By [chandrababu] at [2007-12-26]
# 1

Hi Babu,

You should pass the strong typed parameter as value.

String.Format expects the typed parameter to apply the specied format string.

Change your code as follow as,

String.Format(strFormat,Convert.ToInt64(strValue))

-Mani

ManiD at 2007-9-4 > top of Msdn Tech,Architecture,Architecture General...