unit_to_setunit()

Converts a value from the current G-code unit (G20 for inches, G21 for millimeters) to the unit set in system settings.

Syntax

unit_to_setunit(value)

Parameters

Parameter Type Description
value Number The value in the current G-code unit to convert to the system's unit setting.

Return Value

Examples

Convert 1 inch to system units

unit_to_setunit(1);  // returns 25.4 if settings are in mm, 1 if in inches

Convert 100 mm to system units

unit_to_setunit(100);  // returns 3.937 if settings are in inches, 100 if in mm

Pseudocode:

if (_set_units == _units)
  return value;
else if (_set_units == inches)
  return value / 25.4;
else if (_set_units == millimeters)
  return value * 25.4;

See also

mm_to_unit
unit_to_mm

mm_to_setunit
setunit_to_mm

unit_to_setunit
setunit_to_unit

setunit