The Easy Way
Imagine we fetch the number below from an API, whether it is first- or third-party is not important in this case.
In this case we have gotten the number above, which has 18 decimals, but as we very much love to better the user-experience (UX), and actually make the number more understandable, we would like to ceil to 16 decimals instead.
Yes, it is actually that easy! Although, sometimes we don't care if the number
does up or down, thus using the
Math.round()-function is quite handy
as well. We could simply switch the ceil for our beloved
round, alas, sadly with some numbers, we end up rounding wrong this is
not something we will go into details with, but you can read more
here if you
The TL;DR is that you can simply add Epsilon to the original number, before we do anything else with it. The snippet is written as below.