Copy from java code and paste it directly into c# code, then change (which are in your toDecimalString()
method):
- f.format to f.Format
- digits.length to digits.Length
- b.toString() to b.ToString()
and then paste this class to your code:
public partial class Formatter: IFormatProvider, ICustomFormatter {
public String Format(String format, object arg, IFormatProvider formatProvider=null) {
if(!format.StartsWith("%")||!format.EndsWith("d"))
throw new NotImplementedException();
m_Builder.Append(String.Format("{0:D"+format.Substring(1, format.Length-2)+"}", arg));
return m_Builder.ToString();
}
object IFormatProvider.GetFormat(Type formatType) {
return typeof(ICustomFormatter)!=formatType?null:this;
}
public Formatter(StringBuilder b) {
this.m_Builder=b;
}
StringBuilder m_Builder;
}
Note that the class only implemented the minimum requirement as your question stated, you would need to add the code if your further extend the requirement.