Forums
Dynamic Number formatter using script - Printable Version

+- Forums (https://bdn.bdb.ai)
+-- Forum: BDB Knowledge Base (https://bdn.bdb.ai/forumdisplay.php?fid=13)
+--- Forum: BDB Dashboards Designer (https://bdn.bdb.ai/forumdisplay.php?fid=43)
+---- Forum: BDB Designer Q & A (https://bdn.bdb.ai/forumdisplay.php?fid=16)
+---- Thread: Dynamic Number formatter using script (/showthread.php?tid=592)



Dynamic Number formatter using script - shreekantgosavi - 12-23-2022

const kFormatter = (num) => {
  return Math.abs(num) > 999 ? Math.sign(num) * ((Math.abs(num) / 1000).toFixed(1)) + 'k' : Math.sign(num) * Math.abs(num)
}
var total_calls = changedItem.attributes.data[0].total_calls;
var call_length = total_calls.toString().length;
if(call_length>6){
        var total_calls = kFormatter(total_calls);
        sdk.setValue('label37',total_calls );
}
else
{
        sdk.setValue('label37',total_calls );
}