DroidDB Tip of the Month
DroidDB® Tip for March 2015
Converting a Barcode Value to a Number
When DroidDB reads a barcode, the barcode is a text string. You might want to convert it to a number (perhaps to validate that it is in a certain range of numbers). DroidDB doesn't have an explicit convert function, but it can be done.
When DroidDB evaluates an addition expression, it first converts the two
arguments to numbers and then adds them. So, a string with two characters
(a '1' and a '2') plus another string with two characters (a '3' and a '4')
'12' + '34'
evaluates to a numeric value of 46.
When DroidDB evaluates a concatenation expression, it first converts the two
arguments to strings and then adds them. So, the numeric value 12 concatentated
with the numeric value 34
12 & 34
evaluates to a string '1234'
So, to convert a scanned value to a number, just add 0 to it:
MyBarcode + 0