protected override void setTypedValue(decimal value, byte[] bytes, Dictionary <string, string> settings) { // get integer part and fractional part var integal = (UInt64)Math.Abs(Math.Truncate(value)); var fraction = (UInt64)(Math.Abs(value) - integal).ShiftBy10(this.DecimalPlaces); // number only, fill leading zero and trailing zero var input = integal.ToString() + (this.DecimalPlaces > 0 ? fraction.ToString().PadRight(this.DecimalPlaces, '0') : ""); input = input + (this.IsSigned && value < 0 ? "D" : "F"); input = input.PadLeft(this.LengthOfBytes * 2, '0'); Buffer.BlockCopy(ElementExtend.HexToBytes(input), 0, bytes, 0, bytes.Length); }
protected override void setTypedValue(Decimal value, byte[] bytes, Dictionary <string, string> settings) { // get integer part and fractional part var integal = (UInt64)Math.Abs(Math.Truncate(value)); var fraction = (UInt64)(Math.Abs(value) - integal).ShiftBy10(this.DecimalPlaces); // fill the trailing zero of fraction, and leading zero for the whole var numbers = (integal.ToString() + (this.DecimalPlaces > 0 ? fraction.ToString().PadRight(this.DecimalPlaces, '0') : "") ) .PadLeft(this.NumberOfDigits, '0'); // translate numbers = "F" + String.Join("F", numbers.ToArray()); if (this.IsSigned && value < 0) { numbers = numbers.ReplaceAt(numbers.LastIndexOf('F'), 'D'); } Buffer.BlockCopy(ElementExtend.HexToBytes(numbers), 0, bytes, 0, bytes.Length); }