Question

I am working with an application called TEC-IT Wedge to interface with a grocery scale (for those not in the know a grocery scale is a glorified scale with a scanner.

The scale is connected to a serial port on the PC and thw wedge app monitors that port, the code below handles the scan of the barcode then requests the weight, all of this is working.

Where I am running into the issue is formating the returning weight from the scale.

the data returned from the scale is in the format of ASCII "S11####" so S110004 would be for an item weighing 0.04 pounds and this is how I need to send that wait to the application that we are using the scale to enter data with. For the code below a return of S110004 it returns 00.4

I think I am loosing 0's in the grab of the digits for some reason to place the decimal poit in the correct position.

var cartonverify = Left(DATARAW, 5);
var weightverify = Left(DATARAW, 3);

if (cartonverify == "S08B3") 
   {
    ActivateWindow("Untitled - Notepad");
    SendKeyStrokes(DATARAW.replace(/^S08B3+/i, '') );
    DATA = "";
    WriteToDevice("S11\x0d", 1000);
    }

if (weightverify == "S11")
    {
    ActivateWindow("Untitled - Notepad");
    var cartwieght = Right(DATA, 4);

      if (cartwieght.length == 4)
         {
          var cartounces = Right(cartwieght, 2);
          var cartpounds = Left(cartwieght, 2);
          var WMWeight = cartpounds + "." + cartounces;
          SendKeyStrokes(WMWeight);
          DATA = "";
          }

    }
Was it helpful?

Solution

Re-form your string to something that can be parsed as a number as desired.

var str = 'S110004';
str = str.replace(/S11(\d\d)(\d\d)/, '$1.$2'); // "00.04"

var num = parseFloat(str); // 0.04

Putting the decimal place in at the RegExp step also saves you from having to use division.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top