Percentage in scripted fields


I have divided two fields using below script

return doc['StatusOpen'].value/doc['StatusSent'].value

for this result should be 2/31 = 0.06451 = 6.451% but it's giving 0 %

As I have format as percentage and Numeral.js format pattern as 0,0.[000]%

May I know where I went wrong.

StatusOpen and StatusSent are probably of type int - in this case the / operator is doing an integer division. By casting them to double it should work as expected ( ):
return ((double) doc['StatusOpen'].value)/((double) doc['StatusSent'].value)

Awesome!! it's working @flash1293

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