Sometimes, we need to produce formatted output from a number with decimals. If the output has to be in a designated formatted such as till two places after decimals, we can simply format them using below. It helps specifying the precision correctly :
Below is the function to help you in setting precision till whatever places of decimal you want. If number is limited to only two digits after decimal, it will add zero as suffix, so this might help in some other cases also where you want to show result in money.
Please check the Gist below :
There are several other ways to do it, but I found it more flexible.
Enjoy scripting !!
Below is the function to help you in setting precision till whatever places of decimal you want. If number is limited to only two digits after decimal, it will add zero as suffix, so this might help in some other cases also where you want to show result in money.
Please check the Gist below :
There are several other ways to do it, but I found it more flexible.
Enjoy scripting !!
No comments:
Post a Comment