Skip to content
Astera Technology

Choose whole dots from a supplied label grid

Apply an explicit rounding rule before producing device-grid settings.

Download complete case notes and answer keys ↓

Set the decision and its input

The original grid uses eight dots per millimetre. A supplied 12.3mm dimension maps to 98.4 dots, which is not an executable whole-dot setting. Nearest rounding gives98; ceiling gives99. Neither rule is assumed to be a real printer default.

Filled local test worksheet
CaseInput JSON
Base test{"tenthsMillimetre":123,"dotsPerMillimetre":8,"rounding":"nearest"}
Download editable CSV ↓

Run the supplied comparison

The code multiplies the declared tenths-of-millimetre quantity before rounding at the device grid. A geometric dimension and its selected dot count remain different records for review.

Faulty and required outputs
PathOutput JSON
Faulty path{"dots":98.4,"executableInteger":false}
Required path{"dots":98,"executableInteger":true}
Download editable CSV ↓
Complete local Node24.14.1 programme
import assert from 'node:assert/strict';
const smallWhole=(x,max)=>Number.isSafeInteger(x)&&x>=0&&x<=max;

const run=function run(i,corrected=true){
    if(!['nearest','ceil'].includes(i.rounding)||!smallWhole(i.tenthsMillimetre,1000000)||!smallWhole(i.dotsPerMillimetre,100)||i.dotsPerMillimetre===0)return {held:true};
    const numerator=i.tenthsMillimetre*i.dotsPerMillimetre;
    const dots=corrected?(i.rounding==='ceil'?Math.ceil(numerator/10):Math.floor((numerator+5)/10)):numerator/10;
    return {dots,executableInteger:Number.isInteger(dots)};
  };
const cases=[{"input":{"tenthsMillimetre":123,"dotsPerMillimetre":8,"rounding":"nearest"},"corrected":false,"expected":{"dots":98.4,"executableInteger":false}},{"input":{"tenthsMillimetre":123,"dotsPerMillimetre":8,"rounding":"nearest"},"corrected":true,"expected":{"dots":98,"executableInteger":true}},{"input":{"tenthsMillimetre":123,"dotsPerMillimetre":8,"rounding":"ceil"},"corrected":true,"expected":{"dots":99,"executableInteger":true}},{"input":{"tenthsMillimetre":125,"dotsPerMillimetre":8,"rounding":"nearest"},"corrected":true,"expected":{"dots":100,"executableInteger":true}},{"input":{"tenthsMillimetre":123,"dotsPerMillimetre":8,"rounding":null},"corrected":true,"expected":{"held":true}}];
for(const test of cases){const actual=await run(test.input,test.corrected);assert.deepEqual(actual,test.expected);console.log(actual);}
Download runnable example ↓

Choose from the boundary evidence

The exact 12.5mm boundary gives100 dots without rounding ambiguity. Missing rounding choice is held.

  1. Read the supplied grid density
  2. Convert before rounding
  3. Retain dimension and chosen dots

Hold an unstated rounding rule rather than silently selecting one.

Editable boundary inputs and outputs
ConditionInput JSONExpected output JSON
declared ceiling{"tenthsMillimetre":123,"dotsPerMillimetre":8,"rounding":"ceil"}{"dots":99,"executableInteger":true}
exact integer grid{"tenthsMillimetre":125,"dotsPerMillimetre":8,"rounding":"nearest"}{"dots":100,"executableInteger":true}
rounding choice unknown{"tenthsMillimetre":123,"dotsPerMillimetre":8,"rounding":null}{"held":true}
Download editable CSV ↓

What setting belongs to the base nearest-grid rule?

Show the worked answer

98 whole dots. Keep the original12.3mm dimension; the fractional98.4 is a conversion result, not an executable dot count.

Related resources