Skip to main content

 

With so many numbers that show up within the data bots that use (SSN's, phone numbers, loop counters, etc.), it can be tough at times to know which should be stored as a Number variable and which should be a String. Let's break that down by playing Is It a Number! For each of the examples below, think about how you would store such a value within your own bots, then read through our thoughts on how such data should typically be stored

  1. Age

    • Answer: It Depends!
    • Age can be a bit tricky to consider how best to store it - mainly because it really depends on how the data is intended to be used.
    • If it's going to be used with conditional statements (i.e. to determine if someone is > a certain age) - then it should definitely be stored as a Number variable.
    • If it's going to be used only to grab data from one application/repository/database and move it to another with no arithmetic operations (i.e. I'm not adding anything to it or checking if it's > <), then it can be stored as a String variable without much concern.
      • Of note: if the current use case is to just move it from one app to another but in the future the expectation is to evaluate it for arithmetic operations, best to store it as a number now and deal with any to String operations that may be required as needed.
  2. Dollar Amount

    • Answer: Likely a Number!
    • Dollar amount (like age) is really dependent on the use case...however unlike age, dollar amounts are normally expressed to two decimal places. As such, special considerations should be made as they are cast (converted) from Number to String to ensure that existing decimals are maintained.
    • If you're going to be doing some calculations on the number (determining a bonus, calculating ROI, etc.) it should absolutely be stored as a Number.
    •  If its data that is just going to be used for migrating from app to app, String is probably fine.
  3. Social Security Number or Personal Identification Number

    • Answer: It's a String!
    • Unless you are the Social Security Administration or an organization that is generating new PINs, there is not a likely use case for storing either of these value types as a Number.
    • Remember, consider how this data is being used within your bot/application. It's unlikely you would be incrementing SSNs/PINs, and a mathematical calculation wouldn't make sense either.
    • Even if you did have to match the last 4 of the SSN/PIN to some system of record - you'd likely use a String compare (If package) as opposed to a numerical conditional statement.
  4. Phone Number

    • Answer: It's a String!
    • Phone number (like SSN/PIN) VERY likely to be a String...maybe if your bot is automating the setup of new extensions or something could it be a Number? But 99.5% of the time this should be stored as a String.
    • This is especially true considering that if you tried to store 123-456-7890 as a Number, you're likely to end up with -8,223...which wouldn't really do you any good.
    • If you did have to compare area code (first 3 digits of the phone number) to validate the area the number originated from, you would be best served by using some of the Extract Text capabilities of the String package paired with the String compare operations of the If package.
  5. Loop Counter

    • Answer: It's a Number!
    • Loop counters enable developers to know exactly which iteration of a loop they are on.
    • These counters can be helpful for knowing what row of an HTML table I may be currently interacting with, or what row of a spreadsheet I'm on for updating/inserting cell data.
    • You may at times convert loop counters to String, but it would really only be for the purposes of logging or using the data in an application that only accepts strings.

 

Conclusion

 

The Number variable type is very useful when performing arithmetic operations or when used to establish conditional statements for handling bot logic - but just because something looks like a number doesn't mean it should be stored in a Number variable format. If you haven't used Number variables much in your bot builds so far -what are you waiting for!?!? Start using Number values today to further extend the capabilities of your robotic process automation builds - just make sure you are using them appropriately! Using them already? Let us know on Twitter and Linkedin the different ways you're using Numbers within your bots! 

Be the first to reply!

Reply