Rounding Measured Values in a Custom Table
I have a basic table code here:
FeatureScript 2543;
import(path : "onshape/std/table.fs", version : "2543.0");
annotation { "Table Type Name" : "Measured Values Rhett Test" }
export const variableTable = defineTable(function(context is Context, definition is map) returns Table
precondition
{
}
{
var columns = [];
columns = append(columns, tableColumnDefinition("name", "Name"));
columns = append(columns, tableColumnDefinition("value", "Value"));
columns = append(columns, tableColumnDefinition("description", "Description"));
columns = append(columns, tableColumnDefinition("measure type", "Measure Type"));
var rows = [];
var allVars = getAllVariables(context);
for (var key in keys(allVars))
{
if(match(key, "^rhett_(\\S+)").hasMatch) //I honestly have no idea how this works, but it filters only values that contain this prefix!
rows = append(rows, tableRow({ "name" : key, "value" : allVars[key]}));
}
return table("Measured Values", columns, rows);
});
I need any values that fit the key to be rounded to precision. I have not been able to get the rounding to work. I have tried roundToPrecision in various places but it hasn't made a difference.
Is there another way to go about this?
Comments
-
for (var key in keys(allVars)) { var cellValue = allVars[key]; if (match(key, "^rhett_(\\S+)").hasMatch) cellValue = round(allVars[key], 0.001 * millimeter); rows = append(rows, tableRow({ "name" : key, "value" : cellValue })); }1
