Click here to Skip to main content
15,887,248 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I want to apply this string format "String.Format("{0:0.00}", mytextbox.Text);" to my mytextbox

But I also want it to include following class
C#
public class DoubleFormatter : IFormatProvider, ICustomFormatter
{
  // always use dot separator for doubles
  private CultureInfo enUsCulture = CultureInfo.GetCultureInfo("en-US");

  public string Format(string format, object arg, IFormatProvider formatProvider)
  {
    // format doubles to 2 decimal places
    return string.Format(enUsCulture, "{0:0.00}", arg);
  }

  public object GetFormat(Type formatType)
  {
    return (formatType == typeof(ICustomFormatter)) ? this : null;
  }
}


But the issue is I don't know where to write string format or how.
Inshort confused.
Help me.
Posted
Updated 1-Nov-10 1:24am
v4
Comments
Hiren solanki 1-Nov-10 7:22am    
improved code visibility.
Dalek Dave 1-Nov-10 7:24am    
Edited for Grammar and Readability.
Richard MacCutchan 1-Nov-10 7:52am    
Be patient! You may have to wait one or two days for an answer.

Have you read the documentation? http://msdn.microsoft.com/en-us/library/1ksz8yb7.aspx[^]
 
Share this answer
 
Since you are already using the String.Format in your DoubleFormatter class, there is no need to call it again. Instead directly use your DoubleFormatter class.

Call Format, and pass null as format since that parameter is not used by the function, pass mytextbox.Text as arg, and pass null as formatProvider (since that parameter is not used either). You may need to convert mytextbox.Text to a double, and if that's so then you can use Double.TryParse to do that.
 
Share this answer
 
Comments
krishna kishore58 2-Nov-10 2:24am    
No i'm not getting can u tell me 4m beginning. It's not working. Hope u understand the question

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