question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom format providers

See original GitHub issue

I need to format data, specifically double numbers, with a custom format.

In my case, if the output is requested to be 7 digits, 3 decimals, a value of:

12.3

should be formatted as:

0012300

It is like fixed point, but with no decimal separator char.

I planned to use a custom format provider, but internally the OnFormat methods use ToString, which not support custom format providers (or better, ignore them when dealing with standard type such numbers).

If String.Format was used, instead, it should work.

I am open to any suggestion which helps me to get the desired result

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jehugaleahsacommented, May 25, 2019

I am pushing out a 4.4.0 release. I am going to eventually retire the IColumnDefinition.Preprocessor property. I have created 4 new lambda properties called OnParsing, OnParsed, OnFormatting and OnFormatted that get called before and after parsing and formatting values.

I am also adding support for setting an IFormatProvider on the options object to override the culture settings globally rather than needing to do it on each column individually.

You’ll have to let me know whether the new delegate properties give you the flexibility you need.

0reactions
andrea-rinaldi-microareacommented, May 25, 2019

It worked for me:

.AddColumn(new DoubleColumn("NetWeight") { 
     OutputFormat = "0000.000", 
     OnFormatted = (IColumnContext context, string value) => { return value.Remove(4, 1); } 
}, 7)

values.Add(12.3); // yelds 0012300

I believe I can easily do the reverse job while importing.

Great, many thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to: Define and Use Custom Numeric Format Providers ...
Define a custom format provider ... Implement the IFormatProvider.GetFormat method. GetFormat is a callback method that the formatting method ( ...
Read more >
Custom String Formatting in .NET
Custom format providers give you the ability to use a simple class or classes that provide custom format specifiers and options to pre-existing ......
Read more >
how-to-define-and-use-custom-numeric-format-providers.md
How to: Define and Use Custom Numeric Format Providers .NET gives you extensive control over the string representation of numeric values.
Read more >
Using Custom format With ToString(String, IFormatProvider)
The provider parameter defines the pattern that corresponds to the standard format specifiers, as well as the symbols and names of date and...
Read more >
Custom Formatting | WinForms Controls
The Custom Formatting feature allows you to: format values that are not numeric nor date/time;; implement complex formatting of numeric or date/time values....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found