MetricNumeralExtensions.ToMetric 已过时,使用 MetricNumeralFormats?
MetricNumeralExtensions.ToMetric is obsolete, use MetricNumeralFormats?
我们已将 Humanizer 从 2.8.26 升级到 2.11.10,现在收到以下警告:
'MetricNumeralExtensions.ToMetric(double, bool, bool, int?)' is obsolete: 'Please use overload with MetricNumeralFormats'
是否有关于如何使用 MetricNumeralFormats 的示例?我应该用什么来让它工作?
这是我们当前的代码:
using System;
using Humanizer;
public class Program
{
public static void Main()
{
Console.WriteLine(1234.ToMetric(false, true, 2));
}
}
这里是如何为您的案例使用 MetricNumeralFormats:
using System;
using Humanizer;
public class Program
{
public static void Main()
{
// instead of
Console.WriteLine(1234.ToMetric(false, true, 2));
// do
var decimals = 2;
Console.WriteLine(1234.ToMetric(null, decimals));
}
}
输出
1.23k
1.23k
null
这是您要使用的格式
例如,
var decimals = 2;
var format = MetricNumeralFormats.WithSpace | MetricNumeralFormats.UseName;
Console.WriteLine(1234.ToMetric(format, decimals));
会输出
1.23 kilo
我们已将 Humanizer 从 2.8.26 升级到 2.11.10,现在收到以下警告:
'MetricNumeralExtensions.ToMetric(double, bool, bool, int?)' is obsolete: 'Please use overload with MetricNumeralFormats'
是否有关于如何使用 MetricNumeralFormats 的示例?我应该用什么来让它工作?
这是我们当前的代码:
using System;
using Humanizer;
public class Program
{
public static void Main()
{
Console.WriteLine(1234.ToMetric(false, true, 2));
}
}
这里是如何为您的案例使用 MetricNumeralFormats:
using System;
using Humanizer;
public class Program
{
public static void Main()
{
// instead of
Console.WriteLine(1234.ToMetric(false, true, 2));
// do
var decimals = 2;
Console.WriteLine(1234.ToMetric(null, decimals));
}
}
输出
1.23k
1.23k
null
这是您要使用的格式
例如,
var decimals = 2;
var format = MetricNumeralFormats.WithSpace | MetricNumeralFormats.UseName;
Console.WriteLine(1234.ToMetric(format, decimals));
会输出
1.23 kilo