File tree Expand file tree Collapse file tree 2 files changed +26
-3
lines changed
Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -53,8 +53,11 @@ public AvroDecimal(decimal value)
5353 {
5454 var bytes = GetBytesFromDecimal ( value ) ;
5555
56- var unscaledValueBytes = new byte [ 12 ] ;
57- Array . Copy ( bytes , unscaledValueBytes , unscaledValueBytes . Length ) ;
56+ // Copy the first 12 bytes of the decimal into an array of size 13
57+ // so that the last byte is 0, which is required by the
58+ // BigInteger constructor to ensure the unscaled value is positive.
59+ var unscaledValueBytes = new byte [ 13 ] ;
60+ Array . Copy ( bytes , unscaledValueBytes , 12 ) ;
5861
5962 var unscaledValue = new BigInteger ( unscaledValueBytes ) ;
6063 var scale = bytes [ 14 ] ;
Original file line number Diff line number Diff line change @@ -38,10 +38,30 @@ public void TestAvroDecimalToString(decimal value)
3838 {
3939 var valueString = value . ToString ( ) ;
4040
41- var avroDecimal = new AvroDecimal ( value ) ;
41+ var avroDecimal = new AvroDecimal ( value ) ;
4242 var avroDecimalString = avroDecimal . ToString ( ) ;
4343
4444 Assert . AreEqual ( valueString , avroDecimalString ) ;
4545 }
46+
47+ [ Test ]
48+ public void TestHighPrecisionAvroDecimalToString ( )
49+ {
50+ var value = 4.1748330066797328106875724512m ; // High precision decimal value
51+ var valueString = value . ToString ( ) ;
52+
53+ var avroDecimal = new AvroDecimal ( value ) ;
54+ var avroDecimalString = avroDecimal . ToString ( ) ;
55+
56+ Assert . AreEqual ( valueString , avroDecimalString ) ;
57+
58+ value = - 4.1748330066797328106875724512m ; // High precision decimal value
59+ valueString = value . ToString ( ) ;
60+
61+ avroDecimal = new AvroDecimal ( value ) ;
62+ avroDecimalString = avroDecimal . ToString ( ) ;
63+
64+ Assert . AreEqual ( valueString , avroDecimalString ) ;
65+ }
4666 }
4767}
You can’t perform that action at this time.
0 commit comments