Servicely Administration
Scripting
Money API (BigDecimal)
4 min
when scripting, calculating decimals can often be problematic on certain coding languages however, to remediate this, we have implemented a library within the platform, to allow you to easily and accurately calculate decimal values this is known as “bigdecimal” and for those who have a java background, may have prior exposure to how this operates this is often used for money fields within servicely, due to the fact when you get a money value from a money field, it will be a bigdecimal object creation of a bigdecimal object when creating a bigdecimal object, you can pass in a variety of “types” and then calculate them together an example of this is as per below // bigdecimal can be build // from a number bigdecimal(0 1) // from string bigdecimal("0 1") //or another bigdecimal let dot2 = bigdecimal("0 2") bigdecimal(bigdecimal(0 1) multiply(bigdecimal(3))) available api options true left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type examples // localised format bigdecimal("0 1") withlang("fr fr") format() // 0,1 // strict decimal computation bigdecimal("0 1") multiply(bigdecimal(3)) // 0 30 if this was done with javascript directly, it would be (0 1 3 = 0 30000000000000004)