Message Boards Message Boards

Back

Rounding to Significant Digits

Toggle
Rounding to Significant Digits
Answer
4/13/26 8:34 PM
Is there a way to round to a specific number of significant digits rather than to a decimal place? I'm using variables to create multiple questions in the same slide, but the values are not consistent enough to select a decimal place and have multiplied and divided  values expressed correctly.
0 (0 Votes)

RE: Rounding to Significant Digits
Answer
4/13/26 9:58 PM as a reply to Sandy Powell.
Hi Sandy,
Great question, thanks for posting it here! SmartBuilder doesn't have this functionality, but Javascript can do this natively. So we can pass a couple values into some custom Javascript code (using a Web Object) and have that do the calculations or rounding for us!

See this video here - https://share.smartbuilder.com/public/support/web_object_communication_example_rounding_to_significant_digits.mp4

This same method could be used to pass anything into a self-contained piece of Javascript code. Here's the code from the video, and the lesson is attached.

12345678910111213
<script type="text/javascript">
  function getData(data) {
    const rawValue = data[0]
    const precValue = data[1]

    return Number(rawValue.toPrecision(precValue));
  }

  function setData(data) {
    // not used in this example
    alert("data received: "+data);
  }
</script>
+1 (1 Vote)