File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -5,17 +5,20 @@ namespace Utils
5
5
{
6
6
public static class DecimalUtils
7
7
{
8
- private static NumberFormatInfo whitespaceSeparatorNfi = ( NumberFormatInfo ) CultureInfo . InvariantCulture . NumberFormat . Clone ( ) ;
8
+ // define white space separator number format, it is to be used in all format methods on this class
9
+ private static readonly NumberFormatInfo WhitespaceSeparatorNf = ( NumberFormatInfo ) CultureInfo . InvariantCulture . NumberFormat . Clone ( ) ;
10
+
9
11
static DecimalUtils ( )
10
12
{
11
- whitespaceSeparatorNfi . NumberGroupSeparator = " " ;
13
+ // make the number format use whitespace as thousands separator
14
+ WhitespaceSeparatorNf . NumberGroupSeparator = " " ;
12
15
}
13
16
14
- public static string FormatTrimZeros ( decimal value ) => value . ToString ( "#,0.#############" , whitespaceSeparatorNfi ) ;
17
+ public static string FormatTrimZeros ( decimal value ) => value . ToString ( "#,0.#############" , WhitespaceSeparatorNf ) ;
15
18
16
- public static string FormatTwoDecimalPlaces ( decimal value ) => value . ToString ( "#,0.00" , whitespaceSeparatorNfi ) ;
19
+ public static string FormatTwoDecimalPlaces ( decimal value ) => value . ToString ( "#,0.00" , WhitespaceSeparatorNf ) ;
17
20
18
- public static string FormatFiveDecimalPlaces ( decimal value ) => value . ToString ( "#,0.00000" , whitespaceSeparatorNfi ) ;
21
+ public static string FormatFiveDecimalPlaces ( decimal value ) => value . ToString ( "#,0.00000" , WhitespaceSeparatorNf ) ;
19
22
20
23
public static string FormatTwoDecimalPlacesWithPlusSign ( decimal value ) =>
21
24
( value > 0 ? "+" : "" ) + FormatTwoDecimalPlaces ( value ) ;
You can’t perform that action at this time.
0 commit comments