diff --git a/anbs_cp/Classes/CountConverter.cs b/anbs_cp/Classes/CountConverter.cs
index 8545849..662af0b 100644
--- a/anbs_cp/Classes/CountConverter.cs
+++ b/anbs_cp/Classes/CountConverter.cs
@@ -14,7 +14,8 @@ public sealed class CountConverter : ValueConverter
/// Конструктор класса
///
/// Массив имён размерностей
- public CountConverter (string[] valueNames) : base(valueNames, 1000)
+ /// Знаков после запятой (0, 1, 2)
+ public CountConverter (string[] valueNames, byte decimalPlace = 0) : base(valueNames, 1000, decimalPlace)
{
}
}
diff --git a/anbs_cp/Classes/FileSizeConverter.cs b/anbs_cp/Classes/FileSizeConverter.cs
index dfd3155..5aa77ec 100644
--- a/anbs_cp/Classes/FileSizeConverter.cs
+++ b/anbs_cp/Classes/FileSizeConverter.cs
@@ -14,7 +14,8 @@ public sealed class FileSizeConverter : ValueConverter
/// Конструктор класса
///
/// Массив имён размерностей
- public FileSizeConverter (string[] valueNames) : base(valueNames, 1024)
+ /// Знаков после запятой (0, 1, 2)
+ public FileSizeConverter (string[] valueNames, byte decimalPlace = 2) : base(valueNames, 1024, decimalPlace)
{
}
}
diff --git a/anbs_cp/Classes/ValueConverter.cs b/anbs_cp/Classes/ValueConverter.cs
index 27202b6..8bb82ae 100644
--- a/anbs_cp/Classes/ValueConverter.cs
+++ b/anbs_cp/Classes/ValueConverter.cs
@@ -12,10 +12,12 @@ public abstract class ValueConverter: IValueConverter
///
/// Массив имён размерностей
/// Делитель
- protected ValueConverter (string[] valueNames, long divider)
+ /// Число знаков после запятой
+ protected ValueConverter (string[] valueNames, long divider, byte decimalPlaces)
{
ValueNames = valueNames;
Divider = divider;
+ DecimalPlaces = (byte)(decimalPlaces < 3 ? decimalPlaces : 2);
}
#region Реализация интерфейса
@@ -28,6 +30,12 @@ public abstract class ValueConverter: IValueConverter
/// Делитель
///
public long Divider { get; init; }
+
+ ///
+ /// Знаков после запятой (0, 1, 2)
+ ///
+ public byte DecimalPlaces { get; init; }
+
#endregion
#region Методы
@@ -38,9 +46,18 @@ public abstract class ValueConverter: IValueConverter
/// Конвертирование значение в строку
public string Convert (long value)
{
+ //Получаю разделенное значение
(decimal, int) result = DivideIt(value, 0);
- return $"{result.Item1:F2} {ValueNames[result.Item2]}";
+ //Преобразую значение в строку
+ string resultValue = DecimalPlaces switch {
+ 0 => $"{result.Item1:F0}",
+ 1 => $"{result.Item1:F1}",
+ _ => $"{result.Item1:F2}"
+ };
+
+ //Возвращаю результат
+ return $"{resultValue} {ValueNames[result.Item2]}";
}
@@ -65,8 +82,6 @@ public abstract class ValueConverter: IValueConverter
//... и продолжаем цикл
return DivideIt(value / Divider, count);
-
-
}
#endregion
}
\ No newline at end of file
diff --git a/anbs_cp/Interfaces/IValueConverter.cs b/anbs_cp/Interfaces/IValueConverter.cs
index 56e8a1c..2400136 100644
--- a/anbs_cp/Interfaces/IValueConverter.cs
+++ b/anbs_cp/Interfaces/IValueConverter.cs
@@ -14,4 +14,9 @@ public interface IValueConverter
/// Делитель
///
public long Divider { get; init; }
+
+ ///
+ /// Знаков после запятой (0, 1, 2)
+ ///
+ public byte DecimalPlaces { get; init; }
}
\ No newline at end of file
diff --git a/anbs_cp/anbs_cp.csproj b/anbs_cp/anbs_cp.csproj
index bf3f4ba..def1039 100644
--- a/anbs_cp/anbs_cp.csproj
+++ b/anbs_cp/anbs_cp.csproj
@@ -2,7 +2,7 @@
net7.0
- 2022.1224.1
+ 2023.102.0
Alexander Babaev
ANB Software Components Pack
Library of some useful functions in C# language.
@@ -15,8 +15,8 @@
True
https://git.babaev-an.ru/babaev-an/anbsoftware_componentspack
https://git.babaev-an.ru/babaev-an/anbsoftware_componentspack
- 2022.1224.1
- 2022.1224.1
+ 2023.102.0
+ 2023.102.0
ANBSoftware.ComponentsPack
MIT
6.0
@@ -44,6 +44,7 @@
all
runtime; build; native; contentfiles; analyzers; buildtransitive
+
diff --git a/anbsoftware.componentspack.sln.DotSettings b/anbsoftware.componentspack.sln.DotSettings
index 731bddc..391c6ec 100644
--- a/anbsoftware.componentspack.sln.DotSettings
+++ b/anbsoftware.componentspack.sln.DotSettings
@@ -5,6 +5,7 @@
True
True
True
+ True
True
True
True
\ No newline at end of file