/ src / settings-ui / Settings.UI / Converters / ImageResizerZeroToEmptyStringNumberFormatter.cs
ImageResizerZeroToEmptyStringNumberFormatter.cs
 1  // Copyright (c) Microsoft Corporation
 2  // The Microsoft Corporation licenses this file to you under the MIT license.
 3  // See the LICENSE file in the project root for more information.
 4  
 5  using System;
 6  using System.Globalization;
 7  using Microsoft.UI.Xaml.Controls;
 8  
 9  namespace Microsoft.PowerToys.Settings.UI.Converters;
10  
11  public partial class ImageResizerZeroToEmptyStringNumberFormatter
12  {
13      public string Format(long value) => throw new NotImplementedException();
14  
15      public string Format(ulong value) => throw new NotImplementedException();
16  
17      public string Format(double value) => throw new NotImplementedException();
18  
19      public string FormatDouble(double? value) => value switch
20      {
21          null => string.Empty,
22          0 => string.Empty,
23          _ => value.Value.ToString(CultureInfo.CurrentCulture),
24      };
25  
26      public double? ParseDouble(string text)
27      {
28          if (string.IsNullOrWhiteSpace(text))
29          {
30              return 0.0;
31          }
32  
33          return double.TryParse(text, NumberStyles.Any, CultureInfo.CurrentCulture, out double result) ? result : 0.0;
34      }
35  
36      public long? ParseInt(string text) => throw new NotImplementedException();
37  
38      public ulong? ParseUInt(string text) => throw new NotImplementedException();
39  }