From 5093706a4aeb7f8bf394877b71118e975b194a5d Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Sat, 19 Aug 2023 17:08:38 +0200 Subject: [PATCH] Fix Modifier ValueStr --- Elwig/Helpers/Utils.cs | 8 ++++++++ Elwig/Models/Modifier.cs | 6 ++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Elwig/Helpers/Utils.cs b/Elwig/Helpers/Utils.cs index 3e900b6..3291c42 100644 --- a/Elwig/Helpers/Utils.cs +++ b/Elwig/Helpers/Utils.cs @@ -9,6 +9,7 @@ using System.IO.Ports; using System.Net.Sockets; using Elwig.Dialogs; using System.Text; +using System.Numerics; namespace Elwig.Helpers { public static partial class Utils { @@ -234,5 +235,12 @@ namespace Elwig.Helpers { return Text; } } + + public static string GetSign(T number) where T : INumber + => T.Sign(number) switch { + < 0 => "\u2212", // minus + 0 => "\u00b1", // plus minus + > 0 => "+", + }; } } diff --git a/Elwig/Models/Modifier.cs b/Elwig/Models/Modifier.cs index 78a0fe6..b5ba7ec 100644 --- a/Elwig/Models/Modifier.cs +++ b/Elwig/Models/Modifier.cs @@ -1,3 +1,4 @@ +using Elwig.Helpers; using Microsoft.EntityFrameworkCore; using System; using System.ComponentModel.DataAnnotations.Schema; @@ -43,8 +44,9 @@ namespace Elwig.Models { public virtual Season Season { get; private set; } public string ValueStr => - (Abs != null) ? $"{(Abs.Value < 0 ? "\u00a0-" : "+")}{Math.Abs(Abs.Value)}\u00a0{Season.Currency.Symbol}/kg" : - (Rel != null) ? $"{(Math.Abs(Rel.Value) < 0.1 ? "\u2007" : "")}{(Rel.Value < 0 ? "\u00a0-" : "+")}{Math.Abs(Rel.Value):0.00##\u00a0%}" : ""; + (Abs != null) ? $"{Utils.GetSign(Abs.Value)}{Math.Abs(Abs.Value)}\u00a0{Season.Currency.Symbol}/kg" : + (Rel != null) ? $"{Utils.GetSign(Rel.Value)}{Math.Abs(Rel.Value):0.00##\u00a0%}" : + ""; public override string ToString() { return Name;