Painless script - percentage calculation - returns 0 always due to decimals

I am trying to calculate percentage.

"script": {
	"source": """
	return [ ctx.payload.first.aggregations.success_count.doc_count / (ctx.payload.first.aggregations.success_count.doc_count + ctx.payload.first.aggregations.failure_count.doc_count) * 100) ]
	"lang": "painless"

But it always returns zero which I assume is due to decimal places during the calculation.
Basically, 4/(4+6)*100 should return 40.
Kindly let me know how to fix this.

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