hansva opened a new issue, #9302:
URL: https://github.com/apache/hop/issues/9302

   ### Apache Hop version?
   
   2.20.0
   
   ### Java version?
   
   21
   
   ### Operating system
   
   Other
   
   ### What happened?
   
   When a Script transform output field has type BigNumber, 
`Script.getValueFromScript()` converts the script's result through a `long`, so 
every decimal is lost:
   
   | Result from the script | Code on main | BigNumber written |
   |---|---|---|
   | `2.75` (Double) | `new BigDecimal(((Double) result).longValue())` | `2`, 
silently truncated |
   | `2.75` (JavaScript number) | `new BigDecimal(nb.longValue())` | `2`, 
silently truncated |
   | `"12.345"` (String) | `new BigDecimal(Long.parseLong((String) result))` | 
the transform fails with a `NumberFormatException` |
   
   The Number type keeps the decimals, so the same script gives `2.75` for a 
Number field and `2` for a BigNumber field. BigNumber is the type people choose 
to keep exact decimals, such as amounts, so the silent truncation is the worse 
half of this bug.
   
   Results that are already a `BigDecimal`, or a Byte, Short, Integer or Long, 
are converted correctly.
   
   ### Steps to reproduce
   
   1. Generate rows: one row.
   2. Script transform with a script that sets `amount = 2.75`, and an output 
field `amount` of type BigNumber.
   3. Run the pipeline: `amount` is `2`. With `amount = "12.345"` the transform 
fails.
   
   ### Proposed fix
   
   Keep the decimals:
   
   - Double and JavaScript number results: `BigDecimal.valueOf(doubleValue())`, 
which gives the shortest decimal that represents the double (`2.75`, not 
`2.75000000000000017763568394002504646778106689453125`).
   - String results: `new BigDecimal(string)`.
   
   Two tests in `ScriptTest`: a Double `2.75` gives `2.75`, and the String 
`"12.345"` gives `12.345`.
   
   
   ### Issue Priority
   
   Priority: 2
   
   ### Issue Component
   
   Component: Transforms


-- 
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