Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/OneScript.Core/Commons/ValueFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@

#region Number formatting

public static string FormatNumber(decimal num, FormatParametersList formatParameters)

Check failure on line 87 in src/OneScript.Core/Commons/ValueFormatter.cs

View check run for this annotation

sonar.openbsl.ru qa-bot / SonarQube Code Analysis

src/OneScript.Core/Commons/ValueFormatter.cs#L87

Refactor this method to reduce its Cognitive Complexity from 73 to the 15 allowed.
{
int[] numberGroupSizes = null;

Expand All @@ -104,14 +104,15 @@
string param;
string zeroAppearance;

if (formatParameters.HasParam(NUM_ZERO_APPEARANCE, out param))
if (formatParameters.HasParam(NUM_ZERO_APPEARANCE, out zeroAppearance))
{
zeroAppearance = (param == "") ? "0" : param;
if (zeroAppearance == "")
zeroAppearance = null;
}
else
zeroAppearance = "";

if (num == 0)
if (num == 0 && zeroAppearance is not null)
{
return zeroAppearance;
}
Expand Down Expand Up @@ -174,7 +175,7 @@
{
bool overflov = !ApplyNumericSizeRestrictions(ref num, totalDigits, fractionDigits); ;

if (num == 0)
if (num == 0 && zeroAppearance is not null)
return zeroAppearance;

if (totalDigits == 0)
Expand Down
2 changes: 2 additions & 0 deletions tests/formatting.os
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
юТест.ПроверитьРавенство("0.12346", Формат(Дробь, "ЧЦ=0; ЧДЦ=5; L=en_US"));
юТест.ПроверитьРавенство("", Формат(Дробь, "ЧЦ=5; ЧДЦ=0; L=en_US"));
юТест.ПроверитьРавенство("Z", Формат(Дробь, "ЧЦ=5; ЧДЦ=0; ЧН=Z; L=en_US"));
юТест.ПроверитьРавенство("00,000", Формат(Дробь, "ЧЦ=5; ЧДЦ=0; ЧН=; ЧВН=; L=en_US"));

Дробь = 3.123456789;
юТест.ПроверитьРавенство("3.123457", Формат(Дробь, "ЧДЦ=6; L=en_US"));
Expand Down Expand Up @@ -186,6 +187,7 @@
юТест.ПроверитьРавенство("НОЛЬ", Формат(0, "ЧН='НОЛЬ';"));
юТест.ПроверитьРавенство("0", Формат(0, "ЧН='';"));
юТест.ПроверитьРавенство(" ", Формат(0, "ЧН=' ';"));
юТест.ПроверитьРавенство("00,000.00", Формат(0, "ЧЦ=7; ЧН=; ЧДЦ=2; ЧВН=; L=en_US"));

КонецПроцедуры

Expand Down
Loading