As for truncate, I don’t believe there is such a function. There is a ceiling and floor function, so if you know the signed value, you can use one of those.
I realize that cwinske already addressed your question, however, I uncovered some new code on a more recent post that may also be of interest to you (see https://cl.desmos.com/t/answer-that-is-a-fraction/1077 for more information). I was struggling to round values within a table and found the following code quite helpful:
rounded_value=numericValue(“\round(${value},2)”)
The code was helpful for me because it didn’t require simpleFunction.
Thanks Todd, that’s very helpful and interesting! Blockquote took out one of the backslashes before the “round” (there should be two) but when added that code is fine and is certainly much neater. I also tried using “floor” and “ceiling” in place of “round” but that gave me “NaN”?
Rounding to the nearest integer with the following code was also fine.
rounded_value=numericValue(“\\round(${value})”)
A full explanation of what is possible with this format would be useful? …especially if added to the documentation.
Both simpleFunction and numericValue can do similar things. I’ve started to use simpleFunction more frequently because I ran into some issues with numericValue doing some incorrect calculations with numbers in scientific notation. Apparently it does this once in a while (I think Jay mentioned it somewhere on here). However, numericValue should run fine with your functions.
Sorry, I had experimented more than I described and found ‘floor’ worked when looking for an integer but objected to a “,2” being added if I wanted a number to two decimal places. I do know how to achieve the same effect so it is not an important restriction but I do wish that CL was easier to predict.
These are not specifically CL functions, they’re Desmos calculator functions. You can search for things on the support site. Here’s a link for the floor and ceiling functions. Although I’ll be honest, it can be difficult sometimes to find exactly what you’re looking for.
On screen 11, I want to take the angle measures from the graph component and put them in the table… as integers. The code I tried based on this thread was:
Basic format is “\round(number, decimal places)”. If you don’t have the second parameter, it rounds to the nearest integer. Your issue is that you need ${ } around the whole numericValue code, otherwise it’s just treated as text.
Thank you very much. Based on your response, I tried to break it down further to see what was happening. To better visualize for myself what is happening at each step, this is what I did :
s=numericValue("${graph11.number(z_4)}")
s_round="\round(${s})"
cellContent(1,2):"${s_round}"
Maybe this will help others going forward since multiple nested brackets could get confusing. Thank you again for your help.
You actually want to avoid this step: s=numericValue("${graph11.number(z_4)}")
using s=graph11.number("z_4") is fine, but what you’re actually doing with this numericValue function is taking a number, converting it into a string, then taking the numeric value of that string. For example, we print .000000033 as 3.3e-8. Then, numericValue will interpret that as “3.3 times e, minus 8” or 0.970330033915.
Try entering some some small numbers here and you’ll see that sometimes the numeric value and the numericValue of the numeric value are different.