Skip to content

Enhanced IFormattable/ToString Support #579

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

Closed
tmilnthorp opened this issue Dec 18, 2018 · 1 comment · Fixed by #599
Closed

Enhanced IFormattable/ToString Support #579

tmilnthorp opened this issue Dec 18, 2018 · 1 comment · Fixed by #599

Comments

@tmilnthorp
Copy link
Collaborator

tmilnthorp commented Dec 18, 2018

Following some discussion on #545:

It would be nice to extend the support for IFormattable and ToString.

From the other thread:

So for IFormattable we should make a list:

  • "G" = current default implementation
  • "A1", "A2"... "An" = abbreviation 1 or 2 or n in the list
  • "A" = first abbreviation (equal to "A1")
  • "Q" = quantity name (e.g. "Length")
  • "V" value using default ToString() for double/decimal/etc.
var length = Length.FromMeters( 3.0 );
var str = length.ToString( "A2" ); 

For more complicated strings I think you'd want to specify on a more granular level. We don't want to parse all the number format types. For formatting the value as double, etc. you might want to do the following:

var length = Length.FromMeters( 3.0 );
string.Format( "{0,10:E3} [{1:A1}]", length.Value, length );
@tmilnthorp tmilnthorp changed the title Enhanced IFormattable /ToString Support Enhanced IFormattable/ToString Support Dec 18, 2018
@angularsen
Copy link
Owner

angularsen commented Jul 6, 2019

Updated docs in String Formatting · angularsen/UnitsNet Wiki

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

Successfully merging a pull request may close this issue.

2 participants