Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
StringToDecimalConverter.cs
1using System;
2using System.Globalization;
3using Microsoft.Maui.Controls;
4
6{
7 public class StringToDecimalConverter : IValueConverter
8 {
9 public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
10 {
11 if (value is decimal DecimalValue)
12 return DecimalValue.ToString(culture);
13
14 return string.Empty;
15 }
16
17 public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
18 {
19 // First, check if the input is null or whitespace and handle it accordingly
20 if (value is string Str)
21 {
22 if (string.IsNullOrWhiteSpace(Str))
23 return null; // Return null if the string is empty or whitespace
24
25 if (decimal.TryParse(Str, NumberStyles.Any, culture, out decimal DecimalValue))
26 return DecimalValue;
27 }
28
29 return null; // Return null if the input is null or not a valid decimal
30 }
31 }
32}