Which data type is appropriate for a numerical value of 726.23 stored in the variable totalCost?

September 28, 2013

Preface – This post is part of the Core Apex Tools series.

In this series we’ll cover the Apex fundamentals that I guarantee you’ll use in 100% of your code!

Data types are simply the different types of variables you can have. You can name your variables whatever you like as long as they’re one word. It’s an unwritten rule to have your variables in camel case.

Here’s an example of a String:

String favoriteBeer = 'Mikes Hard Lemonade';

Strings are simply text variables. You use them with all text, email, or picklist type fields in Salesforce. Notice how Strings are always wrapped in single quotes!

Here’s an example of an Integer and Decimal:

Integer numberOfBeers = 6; Decimal bloodAlcoholLevel = 0.15;

These are used in number, currency, and percentage fields in Salesforce. Integers are for number fields without any decimal places.

Booleans:

Boolean isDrunk = true;

Booleans are just either true or false. They’re used with checkboxes in Salesforce.

Dates and DateTimes:

Date courtDate = Date.today().addDays(30); DateTime timePulledOver = DateTime.now();

The difference between Dates and DateTimes is simply that the latter tracks hours, minutes, seconds, and even milliseconds! Note that we used date methods and datetime methods in the example above!

sObjects:

Contact me = [SELECT FirstName, LastName FROM Contact WHERE Email = 'dvdkliu+' LIMIT 1];

Here we queried Salesforce for a record using SOQL and stored the result in an object variable… Apex is so awesome!

sObject is just a fancy name for an object in Salesforce. Custom objects will work too! We could’ve done something similar using a Prisoner__c sObject.

Next post: Data collections – lists, sets, and maps!

Numeric data types are numbers stored in database columns. These data types are typically grouped by:

  • Exact numeric types, values where the precision and scale need to be preserved. The exact numeric types are INTEGER, BIGINT, DECIMAL, NUMERIC, NUMBER, and MONEY.
  • Approximate numeric types, values where the precision needs to be preserved and the scale can be floating. The approximate numeric types are DOUBLE PRECISION, FLOAT, and REAL.

Implicit casts from INTEGER, FLOAT, and NUMERIC to VARCHAR are not supported. If you need that functionality, write an explicit cast using one of the following forms:

CAST(numeric-expression AS data-type) numeric-expression::data-type

For example, you can cast a float to an integer as follows:

=> SELECT(FLOAT '123.5')::INT; ?column? ---------- 124 (1 row)

String-to-numeric data type conversions accept formats of quoted constants for scientific notation, binary scaling, hexadecimal, and combinations of numeric-type literals:

  • Scientific notation:

    => SELECT FLOAT '1e10'; ?column? ------------- 10000000000 (1 row)

  • BINARY scaling:

    => SELECT NUMERIC '1p10'; ?column? ---------- 1024 (1 row)

  • hexadecimal:

    => SELECT NUMERIC '0x0abc'; ?column? ---------- 2748 (1 row)

In This Section

CATEGORY:

A2019

Excel Basic Package

Number Package

Variables

Get to Know Your Datatypes: Number Variable

Beyond clicking their way through applications and making calls to application programming interfaces (APIs), bots use the data gathered from applications to make decisions and perform calculations. In support of these efforts, there is a dedicated variable type to hold numerical values: the Number variable. The number variable can store numeric values (including integers and decimals) from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807, and up to 15 decimal digits. Let’s take a look at a couple of common ways that Number variables are used within bots.

  1. Number Package

    1. The first and most obvious place that Number variables are used is within the Number package.
    2. The Number package allows for basic operations in dealing with Number variable types:
      1. Assign: Assign a specific number to a new variable. This also includes taking arithmetic operations on other Number variables (or by hard-coding numbers) to include addition, subtraction, multiplication, and division.
      2. Decrement: Decrement an existing Number value by a set amount – helpful especially for looping or look-back type operations.
      3. Increment: Increment an existing Number value by a set amount – again helpful for looping, also commonly used with Excel operations.
      4. Random: Assign a random number to a new/existing Number variable. Useful for automating operations that need to look more “human” – i.e. randomized delay between operations on a web site that seems to be tracking traffic or sending a message using randomized text from a list so not every message looks the same.
      5. To String: For displaying in a message box or saving out the number to a log file/Excel. It’s very common to use this operation and its inverse (The String package action to convert a String to a Number)
  2. Loops

    1. The use of Number variables within a loop enables developers to keep track of which iteration, or count, the loop is currently on and take specific operations accordingly.
    2. Numbers are used directly in the Loop package itself (For n times iterator as an example) or through manually incrementing Number values in a loop.
    3. Example:
      1. If a bot needs to loop through an Excel Spreadsheet, the Loop action may be used with the Excel basic iterator to loop through each row in a worksheet. The loop itself returns a record variable for each iteration through the loop (which is the equivalent of an entire row in the spreadsheet). While that’s great, if the bot needs to update/insert data in the spreadsheet, a Number variable would be needed to ensure that the correct row can be updated with the appropriate data.
  3. Conditional Statements

    1. Conditional statements are one of the core tenents of problem-solving.
    2. Conditional statements enable bots to take action as the result of evaluating a condition to be true or not.
      1. These statements enable bots to only take certain actions if a condition is true and to take alternative actions if the condition is not true.
    3. Example:
      1. The “Invoice Payment Bot” is designed to make payments on invoices that are received to automate a function of the accounts payable process. In an effort to reduce fraud, the bot checks the current invoice amount against the last 12 invoice amounts with this vendor to ensure that the invoice amount is within a reasonable range of the 12-month invoice average. A conditional statement based on a number variable is set up within the bot to check to see if the invoice amount exceeds the 12-month invoice average by more than 25%. If it does, the transaction is sent to a user through the AARI interface for final validation before the payment is sent. If the invoice is within 25% of the 12-month invoice average, the payment is made directly through the bot.

Conclusion

The Number variable type is very useful when performing arithmetic operations, inserting/updating data in a spreadsheet, or when used to establish conditional statements for handling bot logic. 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. Using them already? Let us know on Twitter and Linkedin the different ways you’re using Numbers within you bots!

Haven’t tried out the Enterprise A2019 platform yet? Head over to the Enterprise A2019 product page to learn more about product features, request a demo, or try out a free trial today!

Which will be the correct datatype of a variable used for storing the circumference of a circle Mcq?

A float is a data type for storing numbers with decimal places. For example, in calculating the circumference or area of a circle, you often end up with a result that is not a whole number.

Which data type will be used to represent the following data values and why number of months in a year?

Answer: a) The int data type will be used to represent 'Number of months in a year' as it will be an integer i.e. 12.

What kind of data can be stored in a database other than characters and numbers?

Some common data types are as follows: integers, characters, strings, floating-point numbers and arrays. More specific data types are as follows: varchar (variable character) formats, Boolean values, dates and timestamps.

What are the examples of data types?

Common examples of data types.
Boolean (e.g., True or False).
Character (e.g., a).
Date (e.g., 03/01/2016).
Double (e.g., 1.79769313486232E308).
Floating-point number (e.g., 1.234).
Integer (e.g., 1234).
Long (e.g., 123456789).
Short (e.g., 0).

Toplist

Neuester Beitrag

Stichworte