Skip to content

Support for long, float and other numeric types #38

Open
@clement911

Description

@clement911

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions