QuantityFormatter defaults to the "G" format#1450
QuantityFormatter defaults to the "G" format#1450angularsen merged 3 commits intoangularsen:release/v6from
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.
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.
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. |
QuantityFormatterdefaults to the "G" format for null or empty stringQuantityFormatterno longer supports theU/V/Qformats (an exception is thrown)QuantityFormatterexplicitly throws for theCx/PxformatsQuantityFormattershouldn't throw for something like "P1: #.00" (instead it should output something like "P1: 12.34 mg")QuantityFormatterunless explicitly given an incorrectAxspecifier, theQuantityFormatteruses the "default unit abbreviation" - which maybestring.Empty(if none are defined for a given unit)Fixes #1183
Duplicate of #1206
CC @tmilnthorp