Skip to content

Commit cbee202

Browse files
committed
Trim ToString() for units without abbreviation
Scalar, Ratio and other quantities with units that don't have an abbreviation, would result in a trailing whitespace. Example: Scalar.FromAmount(1).ToString() == "1 "
1 parent 6443d04 commit cbee202

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

UnitsNet/QuantityFormatter.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ public static string Format<TUnitType>(IQuantity<TUnitType> quantity, string for
124124
/// <returns>The string representation.</returns>
125125
public static string Format<TUnitType>(IQuantity<TUnitType> quantity, string format, IFormatProvider? formatProvider)
126126
where TUnitType : Enum
127+
{
128+
return FormatUntrimmed(quantity, format, formatProvider).Trim();
129+
}
130+
131+
private static string FormatUntrimmed<TUnitType>(IQuantity<TUnitType> quantity, string format, IFormatProvider? formatProvider)
132+
where TUnitType : Enum
127133
{
128134
formatProvider ??= CultureInfo.CurrentUICulture;
129135

0 commit comments

Comments
 (0)