ianmcook commented on PR #341:
URL: https://github.com/apache/arrow-js/pull/341#issuecomment-4663543386

   I think I’m hitting the same underlying issue through `Table.toString()`: 
the decimal type and scale are preserved, but stringification prints the raw 
unscaled integer:
   
   ```js
   import { Decimal, makeTable, makeVector } from 'apache-arrow';
   
   const type = new Decimal(2, 5, 128); // scale, precision, bitWidth
   
   // Unscaled integer 1999, representing 19.99 with scale 2.
   const price = makeVector({
     type,
     data: new Uint32Array([1999, 0, 0, 0]),
   });
   
   const table = makeTable({ price: price });
   
   console.log(String(price.type));
   console.log('value.toString():', String(price.get(0)));
   console.log('value.valueOf(scale):', price.get(0).valueOf(type.scale));
   console.log(table.toString());
   ```
   
   Actual output:
   
   ```text
   Decimal[5e+2]
   value.toString(): 1999
   value.valueOf(scale): 19.99
   [
     {"price": 1999}
   ]
   ```
   
   Expected: `Table.toString()` would format the decimal using the field type’s 
scale, e.g. `19.99`, matching the logical `decimal128(5, 2)` value.
   
   For comparison, PyArrow prints the same logical value using scale metadata:
   
   ```python
   from decimal import Decimal
   import pyarrow as pa
   
   table = pa.table({
       "price": pa.array([Decimal("19.99")], type=pa.decimal128(5, 2)),
   })
   
   print(table)
   ```
   
   Output:
   
   ```text
   pyarrow.Table
   price: decimal128(5, 2)
   ----
   price: [[19.99]]
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to