Skip to content

Commit 2e5f29f

Browse files
committed
specify NumberFormatInfo explicitly
1 parent 83e77f0 commit 2e5f29f

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/Smdn.Fundamental.SIPrefix/Smdn.Formats/SIPrefixNumberFormatter.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public class SIPrefixNumberFormatter : IFormatProvider, ICustomFormatter {
2424
*/
2525
public bool IsReadOnly { get; }
2626

27+
private readonly NumberFormatInfo numberFormatInfo;
28+
2729
private string byteUnit;
2830

2931
public string ByteUnit {
@@ -71,12 +73,12 @@ protected SIPrefixNumberFormatter(CultureInfo cultureInfo, bool isReadOnly)
7173
throw new ArgumentNullException(nameof(cultureInfo));
7274

7375
this.IsReadOnly = isReadOnly;
74-
// this.cultureInfo = cultureInfo;
7576

7677
const string singleSpace = " ";
7778

7879
switch (cultureInfo.TwoLetterISOLanguageName) {
7980
case "ja":
81+
numberFormatInfo = cultureInfo.NumberFormat;
8082
byteUnit = "バイト";
8183
valuePrefixDelimiter = singleSpace;
8284
prefixUnitDelimiter = string.Empty;
@@ -85,6 +87,7 @@ protected SIPrefixNumberFormatter(CultureInfo cultureInfo, bool isReadOnly)
8587
break;
8688

8789
default:
90+
numberFormatInfo = NumberFormatInfo.InvariantInfo;
8891
byteUnit = "Bytes";
8992
valuePrefixDelimiter = singleSpace;
9093
prefixUnitDelimiter = singleSpace;
@@ -166,17 +169,24 @@ public string Format(string format, object arg, IFormatProvider formatProvider)
166169

167170
if (fileSizeFormat) {
168171
if (aux == 0)
169-
ret.Append(val.ToString("F0"));
172+
ret.Append(val.ToString("F0", numberFormatInfo));
170173
else
171-
ret.Append(val.ToString("F1"));
174+
ret.Append(val.ToString("F1", numberFormatInfo));
172175

173176
unitString = abbreviate ? byteUnitAbbreviation : byteUnit;
174177
}
175178
else {
176-
if (digits == 0)
177-
ret.Append(((long)val).ToString("D"));
178-
else
179-
ret.Append(val.ToString("F" + digits.ToString("D", provider: NumberFormatInfo.InvariantInfo)));
179+
if (digits == 0) {
180+
ret.Append(((long)val).ToString("D", numberFormatInfo));
181+
}
182+
else {
183+
ret.Append(
184+
val.ToString(
185+
"F" + digits.ToString("D", provider: NumberFormatInfo.InvariantInfo),
186+
numberFormatInfo
187+
)
188+
);
189+
}
180190
}
181191

182192
if (!abbreviate && 0 < prefixes[aux].Length)

0 commit comments

Comments
 (0)