Rounding & Truncating

Searching the forum, I found a way to round a value to 2 decimal places (useful in CL documentation?)

rounded_value = simpleFunction("\operatorname{round}(k,2)",“k”).evaluateAt(value)

Using this I can also round to an integer by setting the number of decimal places to zero but is there a better way?

Also, is there an operator for ‘truncate’? I tried that and ‘trunc’ in the above but no success.

This would round to the nearest integer, but you could also use a graph if you have one available in the activity.

rounded_value = simpleFunction("\operatorname{round}(k)",“k”).evaluateAt(value)

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.

Perfect! Thank you for your help.

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 for more information). I was struggling to round values within a table and found the following code quite helpful:


The code was helpful for me because it didn’t require simpleFunction.

1 Like

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.


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.

To get floor or ceiling, try this:


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.

1 Like

Thanks, looks like there are some more functions there to explore as well!

You can do explicit truncation with the following function:


No need to know the sign of the input in advance: Explicit Truncation

Need to be able to pick the number of digits of truncation and aren’t too worried about piecewise case handling?


Here you go: Truncate