- Gina6262Asked on January 28, 2015 at 09:03 AM
I only see round, but I need to truncate or remove the decimals from a calculated number.
I've put a placeholder in the calculation on the form that uses round() for now, but that isn't the calculation I need.I also need to use just the year from a date field in another calculation.
- BenAnswered on January 28, 2015 at 10:12 AM
You could always set the jotform to not show the decimal places or show different number of decimal places.
To do that open the Form Calculation wizard and click on advanced in the bottom part of it.
Once you do you will see the options as shown here:
Setting it to 0 will make it not show any decimal places.
I have also moved your question about the year to a new thread here: http://www.jotform.com/answers/505146 where we will be replying shortly.
- Gina6262Answered on January 28, 2015 at 10:18 AM
Just for clarification.... this isn't just the display of the answer that is missing the decimals, it's the actual value, right?
I need it for further calculations is why I ask.
- BenAnswered on January 28, 2015 at 10:34 AM
It will round up the number - similar as round() would.
There are 3 alternatives:
1. round() - rounds up the number to the nearest integer with precedence to up
round(2.5) = 3
round(2.4) = 2
2. ceil() - rounds up to the first bigger integer
ceil(2.5) = 3
ceil(2.1) = 3
3. floor() - rounds up to the first lower integer
floor(2.5) = 2
floor(2.9) = 2
Hope this helps.
- Gina6262Answered on January 28, 2015 at 10:35 AM
So, looks like it isn't actually truncating... it's rounding
What I'm trying to do is collapse the number
So 15 becomes 6, 22 becomes 4 etc.
Let's take 15 for the current year.
15/10 = 1.5 so I want that to show 1 for the 10's column
And then for the 1's column can take the number in the tens multiply by 10 and substract from year.
15 - (10*1) = 5
But when I do the display as shown above... the 10's look right
But when I do the calc for the 1's it's not (because it's rounding)
If the year has the last digit 4 or under it works.
Hope this is clear.
- BenAnswered on January 28, 2015 at 10:38 AM
Based on your reply I would advise to check floor() since it will always round to the nearest lower number so it will work just as if it is under 5.
- BenAnswered on January 28, 2015 at 11:22 AM
Yes, we crossed replies.. that was perfect!!!!
Thanks so much.
Yes, I had noticed that as well :)
I am glad that it is what you were after :)
Do let us know if you have any further questions and we would be happy to answer them.