-
Notifications
You must be signed in to change notification settings - Fork 384
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
QuantityFormatter defaults to the "G" format #1450
QuantityFormatter defaults to the "G" format #1450
Conversation
- QuantityFormatter no longer supports the U/V/Q formats - QuantityFormatter explicitly throws for the Cx/Px formats
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After you've finished reviewing these, let's move them to the QuantityFormatterTests.cs
- none of the tests in this file should reference the QuantityFormatter
.
private static string FormatWithValueAndAbbreviation<TUnitType>(IQuantity<TUnitType> quantity, string format, IFormatProvider formatProvider) | ||
where TUnitType : Enum | ||
{ | ||
var abbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(quantity.Unit, formatProvider); | ||
return string.Format(formatProvider, $"{{0:{format}}} {{1}}", quantity.Value, abbreviation); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another change from the existing behavior (which I think is necessary) is that the when in the case of the "standard numeric format" (which is the default for Volume.FromAuTablespoon(1).ToString()
) we again rely on the default abbreviation (possibly string.Empty
) instead of throwing, as would be the case if you attempt this on a previous version (e.g. v5):
Volume.FromAuTablespoon(1).ToString("g"); // FormatException??
@angularsen Eh, just wanted to note that I personally have no preference here regarding whether "G" or "S" is the default format- I just took the #1206 as a starting point.. Same goes for the exceptions. The removal of the extra formats- I'm very happy about... |
I think G is the better choice actually, since S may subtly hide precision they were interested in. If they want pretty formatting they should take control instead of us trying to guess if they prefer scientific notation or fixed point. I am no longer sure the S format is a good idea, but I guess we can keep it since it is now opt-in instead of default. |
QuantityFormatter
defaults to the "G" format for null or empty stringQuantityFormatter
no longer supports theU
/V
/Q
formats (an exception is thrown)QuantityFormatter
explicitly throws for theCx
/Px
formatsQuantityFormatter
shouldn't throw for something like "P1: #.00" (instead it should output something like "P1: 12.34 mg")QuantityFormatter
unless explicitly given an incorrectAx
specifier, theQuantityFormatter
uses the "default unit abbreviation" - which maybestring.Empty
(if none are defined for a given unit)Fixes #1183
Duplicate of #1206
CC @tmilnthorp