| | 1 | | using ExtendedNumerics; |
| | 2 | | using System.Text.RegularExpressions; |
| | 3 | | using ValidateLib.ErrorsAndWarnings.Errors; |
| | 4 | | using ValidateLib.Metadata.Descriptors; |
| | 5 | |
|
| | 6 | | namespace ValidateLib.TabularData.Datatypes.NumericDatatypes |
| | 7 | | { |
| | 8 | | public class DecimalDT : NumericBaseDT |
| | 9 | | { |
| 1 | 10 | | public DecimalDT() { } |
| 1 | 11 | | public DecimalDT(string stringValue) : base(stringValue) |
| | 12 | | { |
| 1 | 13 | | CheckLexicalSpace(); |
| 1 | 14 | | Value = BigDecimal.Parse(this.stringValue); |
| 1 | 15 | | ResolvePercentPermileExponent(); |
| 1 | 16 | | } |
| | 17 | |
|
| 1 | 18 | | public DecimalDT(string stringValue, FormatDescriptor format) : base(stringValue, format) |
| | 19 | | { |
| | 20 | | //Contains Exponent |
| 1 | 21 | | if (Exponent != 1) |
| 1 | 22 | | ErrorFactory.ThrowDatatypeValidationError(stringValue); |
| | 23 | | // Contains special type NaN.... |
| 1 | 24 | | if (SpecialType != SpecialTypes.Normal) |
| 1 | 25 | | ErrorFactory.ThrowDatatypeValidationError(stringValue); |
| 1 | 26 | | } |
| | 27 | |
|
| | 28 | |
|
| | 29 | |
|
| | 30 | | void CheckLexicalSpace() |
| | 31 | | { |
| | 32 | |
|
| 1 | 33 | | string pattern = @"^(\+|-)?([0-9]+(\.[0-9]*)?|\.[0-9]+)$"; |
| 1 | 34 | | if (!Regex.IsMatch(stringValue, pattern)) |
| 1 | 35 | | ErrorFactory.ThrowDatatypeValidationError(stringValue); |
| 1 | 36 | | if (Exponent != 1) |
| 1 | 37 | | ErrorFactory.ThrowDatatypeValidationError(stringValue); |
| 1 | 38 | | if (SpecialType != SpecialTypes.Normal) |
| 0 | 39 | | ErrorFactory.ThrowDatatypeValidationError(stringValue); |
| 1 | 40 | | } |
| | 41 | |
|
| | 42 | | override public int CompareTo(BaseDT? other) |
| | 43 | | { |
| 0 | 44 | | if (other is null) |
| 0 | 45 | | return 1; |
| 0 | 46 | | if (other is not DecimalDT) |
| 0 | 47 | | throw new ArgumentException(); |
| 0 | 48 | | var typedOther = (DecimalDT)other; |
| 0 | 49 | | return Value.CompareTo(typedOther.Value); |
| | 50 | |
|
| | 51 | | } |
| | 52 | | } |
| | 53 | | } |