質問

私にはクラスがあり、に関連する機能を再現したい ToString("0.0000") 他のいくつかの数値フォーマットのもの。これはどうすればいいですか?

役に立ちましたか?

解決

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