문제

I have class and I want to reproduce the functionality associated with ToString("0.0000") as well as some other numerical formatting stuff. How can this be done?

도움이 되었습니까?

해결책

Regular expressions are probably your best bet.

다른 팁

class MyNumber : IFormattable
{
   decimal value;
   public MyNumber(decimal value)
   { this.value = value; }

   string IFormattable.ToString(string format, IFormatProvider formatProvider)
   { return value.ToString(format, formatProvider); }

   public string ToString(string format)
   { return ((IFormattable)this).ToString(format, System.Globalization.CultureInfo.CurrentCulture); }
}

class Program
{
   static void Main(string[] args)
   {
      MyNumber num = new MyNumber(3.1415926m);
      Console.WriteLine(num.ToString("0.0000"));
      Console.WriteLine("{0:0.0000}", num);
   }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top