What is JotForm?
JotForm is a free online form builder which helps you create online forms without writing a single line of code. No sign-up required.
At JotForm, we want to make sure that you’re getting the online form builder help that you need. Our friendly customer support team is available 24/7.
We believe that if one user has a question, there could be more users who may have the same question. This is why many of our support forum threads are public and available to be searched and viewed. If you’d like help immediately, feel free to search for a similar question, or submit your question or concern.
Form Calculation - how to remove the decimal places - truncate a number?Asked by Gina6262 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.
date field year from placeholder OR
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.
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.
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.
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.
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.
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.