Skip to content

Commit

Permalink
Merge pull request #468 from Sidekick-Poe/bugfix/limit-double-prop-di…
Browse files Browse the repository at this point in the history
…gits

Limit the precision of double property filters
  • Loading branch information
leMicin authored Jan 8, 2025
2 parents 3c30d3d + f4d80b4 commit a11f7cc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal DoublePropertyFilter(

public double? Min { get; set; }

public double? Max { get; set;}
public double? Max { get; set; }

/// <summary>
/// Normalize the Min value with NormalizeValue.
Expand All @@ -29,11 +29,11 @@ public void NormalizeMinValue()

if (value > 0)
{
Min = (int)Math.Max((1 - (decimal)NormalizeValue) * value, 0);
Min = Math.Round((double)Math.Max((1 - (decimal)NormalizeValue) * value, 0), 2);
}
else
{
Min = (int)Math.Min((1 + (decimal)NormalizeValue) * value, 0);
Min = Math.Round((double)Math.Min((1 + (decimal)NormalizeValue) * value, 0), 2);
}
}

Expand All @@ -49,11 +49,11 @@ public void NormalizeMaxValue()

if (value > 0)
{
Max = Math.Max(Math.Max(value + 1, (1 + (double)NormalizeValue) * value), 0);
Max = Math.Round(Math.Max(Math.Max(value + 1, (1 + (double)NormalizeValue) * value), 0), 2);
}
else
{
Max = Math.Min(Math.Max(value + 1, (1 - (double)NormalizeValue) * value), 0);
Max = Math.Round(Math.Min(Math.Max(value + 1, (1 - (double)NormalizeValue) * value), 0), 2);
}
}

Expand Down
20 changes: 10 additions & 10 deletions src/Sidekick.Common.Ui/Forms/FormNumberSmall.razor
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<div class="flex items-center flex-nowrap gap-1">
@if (!string.IsNullOrEmpty(Label))
{
<label for="@Id"
class="block text-base font-medium dark:text-zinc-200">
@Label
</label>
}
<div class="flex items-center flex-nowrap gap-1">
@if (!string.IsNullOrEmpty(Label))
{
<label for="@Id"
class="block text-base font-medium dark:text-zinc-200">
@Label
</label>
}

<input id="@Id"
@onchange="OnChange"
value="@InternalValue"
class="@UiClasses.FormInputClasses p-[2px] text-sm min-w-0 grow"/>
class="@UiClasses.FormInputClasses p-[2px] text-sm min-w-0 grow" />
</div>

@code {
Expand Down Expand Up @@ -38,7 +38,7 @@
{
if (double.TryParse(args.Value?.ToString(), out var doubleValue))
{
await ValueChanged.InvokeAsync(doubleValue);
await ValueChanged.InvokeAsync(Math.Round(doubleValue, 2));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
else
{
<ItemPropertyText Label="@Filter.Text"
Value="@Filter.Value.ToString("0.00")"/>
Value="@Filter.Value.ToString("0.##")"/>
}
</FormCheckbox>
</div>
Expand Down

0 comments on commit a11f7cc

Please sign in to comment.