Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET formatted Numeric Converter? #408

Open
devmaestro1 opened this issue Jul 16, 2021 · 0 comments
Open

.NET formatted Numeric Converter? #408

devmaestro1 opened this issue Jul 16, 2021 · 0 comments

Comments

@devmaestro1
Copy link

devmaestro1 commented Jul 16, 2021

Hi - first up, thanks for this excellent library!

I have been looking through the code (and StackOverflow) to see if there was some way to format a number using the standard .NET format specifiers.

For example, I would have expected that if you wanted to use a decimal field, you could also specify the output/input format like "0.00".

It seems that this is possible via a CustomConverter, however wouldn't it be desirable to have a built-in converter kind (ConverterKind.Numeric or ConverterKind.Generic) that allows you to do this? I imagine the part of the code would look as follows:

  ```
   public class NumberFormatter : ConverterBase
    {
        public NumberFormatter()
        {
            NumberFormat = string.Empty;
            AdditionalFormat = string.Empty;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="numberFormat"></param>
        /// <param name="additionalFormat"></param>
        public NumberFormatter(string numberFormat, string additionalFormat)
        {
            NumberFormat = numberFormat;
            AdditionalFormat = additionalFormat;
        }

        /// <summary>
        /// The C# style numeric expression
        /// </summary>
        public string NumberFormat { get; set; }
        /// <summary>
        /// Currently unused
        /// </summary>
        public string AdditionalFormat { get; set; }

        public override object FieldToString(object val)
        {
            return val.ToString(NumberFormat, CultureInfo.InvariantCulture);
        }
    }

Have I missed something or does this feature not exist?

P.S. I unfortunately cannot use the custom converter as I am creating a ClassFromString which means I cannot reference the custom type without injecting the class source. It's a potential solution, just not an ideal one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant