Issue truncating calculated number
I have a calculation that returns the difference in months between two dates. However no matter what I do, the resulting output has two decimal places, and I want it to be an integer.
Here is my code:
var start = moment(@Date of Engagement Start);
var end = @All of Date of Business Transaction[0] != null ? moment(@All of Date of Business Transaction[0]) : moment();
Math.ceil(end.diff(start, 'months', true))
Math.ceil() on its own should return an integer. But I have also tried this with a combination of toFixed() and parseInt(), and that doesn't work either. I tried Math.trunc() as well but Podio did not recognize it as a valid function. Out of curiosity I tried parseFloat() and toFixed(4), but even that resulted in just two decimal places being displayed.
The reference for the diff() function says that it truncates the result to zero decimal places by default. I have the third parameter here set to false only because I realized I wanted the ceil of the result, not the trunc, but even when I tried the default setting, still I got a 2-decimal float.
Can someone point out where I'm going wrong or what else I could try to force an integer result? Thanks in advance.
Please sign in to leave a comment.
Comments
1 comment