How to use painless BigDecimal in java code?

I use painless to update doc. how to use BigDecimal to finish it ? Using Elasticsearch 6.8.1.
Script JavaDoc
Script construtor is:

public Script (ScriptType type,
              java.lang.String lang,
              java.lang.String idOrCode,
              java.util.Map<java.lang.String, java.lang.Object> params)

My Code is:

StringBuilder script = new StringBuilder();
Map<String, Object> params = new HashMap<>();
params.put("poundageRate", poundageRate.doubleValue());
Script scriptObj = new Script(INLINE, DEFAULT_SCRIPT_LANG, script.toString(), params);

My Question is:
How to let ctx._source.amount*params.poundageRate using BigDecimal method
multiply and setScale

new BigDecimal("ctx._source.amount").multiply(new BigDecimal("params.poundageRate")).setScale(2, HALF_UP).stripTrailingZeros()

Thanks a lot i will appreciate it

I had solved this problem. reference: How to use elasticsearch painless BigDecimal in java code? - Stack Overflow

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.