ExcelNumberFormat icon indicating copy to clipboard operation
ExcelNumberFormat copied to clipboard

Support for long, float and other numeric types

Open clement911 opened this issue 1 year ago • 0 comments

Formatting numbers only works with double, int and short. Other numeric types should be supported, such as byte, sbyte, ushort, uint, long, ulong, float, decimal.

  var format = new NumberFormat("#,##0");

  format.Format(1234, CultureInfo.InvariantCulture);//1,234 => OK
  format.Format(1234d, CultureInfo.InvariantCulture);//1,234 => OK
  format.Format(1234f, CultureInfo.InvariantCulture);//1234 => Fail
  format.Format(1234L, CultureInfo.InvariantCulture);//1234 => Fail
  format.Format(1234m, CultureInfo.InvariantCulture);//1234 => Fail
  format.Format((ushort)1234, CultureInfo.InvariantCulture);//1234 => Fail

I believe it's because the evaluator only checks for double, int and short. I might be more appropriate to try casting to IConvertible and use IConvertible.ToDouble.

Similarly it would be nice to support System.DateOnly and System.TimeOnly

clement911 avatar Jun 20 '23 06:06 clement911