Numbers
Numbers are integers or floating point numbers. In Panorama X, both are 64 bit. Integers are the number zero and the positive and negative whole numbers, that is, they are not expressed as a fraction or decimal number. Floating point numbers are all non-whole real numbers. They can be expressed as a set of digits and an exponent. You can learn more technical details about floating point numbers at Floating Point Numbers.

#### Combining Numbers

When you combine numeric types in Panorama, here is what happens to the result:

Operator | Operand 1 | Operand 2 | Result
--- | --- | --- | ---
+, -, * | Integer | Integer | Integer
+, -, * | Integer | Float | Float
+, -, * | Float | Integer | Float
+, -, * | Float | Float | Float
/ | Any | Any | Float
\ | Any | Any | Integer

#### Converting numbers to text

You may convert numbers to text by concatenating a number with a non-number, or by applying a variety of functions. If no pattern is specified, a floating point number will round to six significant digits. For example, if the result of a function is `12345.6789`, it will be displayed, in a text display object, for example, as `12345.7` if no pattern is applied. If you need to display more decimal places, then use a pattern, such as

    pattern(12345.6789,”$#,.##”) ☞ $12,345.68

Six functions convert numbers to text:

Str( function: The string function will convert an integer—as text—exactly as the integer appears, from `str(-9223372036854775807)` to `str(9223372036854775807)`. Integers greater or less than those numbers are not correct. Floating point numbers in Panorama will be handled exactly correctly up to 15 digits.

pattern( function: The pattern function converts numbers to text in a wide variety of ways of your creation. See the Numeric Patterns for more details. The pattern function can output up to 15 significant digits. Patterns now include an option for engineering notation, e.g. `pattern(number,”###.###e”)`, where e is always a multiple of 3.

zbPattern( function: This is the same as the pattern function except that zero value output will be left blank. For example, the formula `zbpattern(number,”$#,.##”)` will return blank if 0 is the original number, `$1.00` if 1 is entered, and `$7,542.00` if 7542 is entered.

pluralPattern( function: See zbpattern( for using correct English syntax, by adding an “s”, or not, and using “is” or “are” as appropriate and changing nouns to the correct form, within limits, of course.

radixstr( converts a number into a text string expressed in a different number base, from 2 to 32, or to binary. You may enter binary, octal, or hex for bases 2, 8, and 16. like this:

    radixstr("hex",1234) ☞ 00000000000004D2

    radixstr(17,1234) ☞ 44A

hexstr( is merely a subset of the radixstr( function – it converts to a text string of the base 16 number.

#### Converting anything to a floating point number.

float(: This function will convert any type of value to a floating point value, including text, integers, or fixed point numbers. For example,

    float(3) ☞  3.0000
    float(“3”)  ☞  3.0000
    float(“anytext”) ☞  0 and
    float(3.5) ☞ 3.5000

In most situations Panorama converts integers to floating point automatically when necessary and you don’t need the float( function. For example, division automatically converts to floating point.

    3/4 ☞ 0.75

#### Converting a floating point number to an integer.

You may also convert floating point numbers to integers with three functions.

int( which truncates toward -infinity. So

    int (4.5) ☞ 4

and

    int(-4.5) ☞ -5

ceil( truncates toward positive infinity. So

    ceil(4.5) ☞ 5

and

    ceil(-4.5) ☞ -4

fix( truncates toward 0. So

    fix(4.5) ☞ 4

and

    fix(-4.5) ☞ -4

#### Rounding Floating Point Numbers

Rounding works like traditional rounding with one wrinkle:

    round(4.5,1) ☞ 5

but use `round(-4.5,-1)` if you want to round to –5. Query, if you have a variable of unknown sign (“+” or “-“?), how do you handle that? This oddity may be changed in a later release of Panorama so the second operand is always positive.

HexStr( Panorama X supports the use of hexadecimal (base 16) numbers. To express a hexadecimal constant, begin the string with `0x`.

#### Converting base–10 numbers to base–16, i.e. hexadecimal

Several functions can convert base–10 numbers to hexadecimal numbers: hexbyte, hexword, hexlong, and hexstr. See the details in the Panorama X Help pages: hexbyte(, hexword(, hexlong(, and hexstr(.

#### Special Floating Point Values

There are two special floating point values: INF (infinity) and NAN (not a number). For example, dividing by zero returns inf, so

    1/0 ☞ inf

The result is treated as a valid result (but not a valid number), not an error. The function infinity() is equivalent to dividing by zero. So

    2/0=infinity() ☞ true

Since Panorama does not accommodate imaginary numbers, the nan has been created to handle operations that return imaginary numbers. So the function

    sqr(-2) ☞ nan

You may test a result to see if it is a valid number with the function validnumber(, which returns true or false. For example,

    validnumber(-2) ☞ -1, i.e. true

and

    validnumber(sqr(-2)) ☞ 0, i.e. false

In spite of the existence of the infinity( function, infinity is still not a valid number, i.e.,

    validnumber(2/0) ☞ 0

You can test to see if a numeric value is valid with the nan( function, which is true if the value tested is invalid. For example,

    nan(5/2) ☞ 0, i.e., false

while

    nan(5/0) ☞ -1, i.e. true
    nan(sqr(-1) ☞ -1, i.e. true

You may also use the divzero( function to return zero instead of nan if you divide a number be zero, or you may use the divzeroerror( function to return an error if you divide a number by zero or the actual result if the denominator is not zero.

#### The mod function

The mod function returns the remainder when operand 1 is divided by operand 2. It can help when working with numbers in some clever ways. You can check if numbers are even or odd with the mod function.

    x mod 2 ☞  1,which is true

if x is odd. (Note that any floating point operand will be converted to an integer before the calculation is made.) You may find numbers divisible by any integer, so `(x mod y)=0` will return true whenever x is evenly divisible by y. You could also select every x number of records by using `(seq() mod x)=0`, which will be true for every x records beginning with record number x.

While you are working with true/false formulas, remember that false is 0 and that every other number is true. One true value does not necessarily equal another true value, but every false value will equal every other false value.

The mod function will truncate floating point operands back to the decimal, so, for example,

    6.8 mod 2.2 ☞ 0

Mod may also return a negative number.

    -7 mod 2 ☞ -1

#### Random numbers

Panorama has two functions for generating random numbers, the randominteger( and rnd( functions. `Randominteger(x,y)` will generate a random integer between x and y. rnd( will generate a random number between 0 and 1.

For other topics regarding numbers, see the help pages for the trig functions, time, various date and superdate functions (which are stored as integers), statistical functions, zip codes, irrational numbers, pi, and Euler’s number, logarithmic functions, nth function to convert numbers into ordinals, leading zeros, financial functions, and scientific notation.

See Also

- analyzedialog -- opens the standard Analyze dialog.
- average -- calculates averages and sub-averages for the selected records in the current field.
- calendardate( -- helps in creating monthly calendars.
- calendarday( -- helps in creating monthly calendars.
- city( -- looks up the name of a city associated with a US zip code.
- cityzip( -- returns the lowest zip code associated with a city.
- cityzips( -- returns a list of zip codes associated with a city.
- collapse -- hides the detail records associated with the currently active summary record.
- collapsetosummary -- collapses to the next higher summary level.
- cos( -- calculates the cosine of an angle.
- count -- counts all non-empty data cells for the current field.
- county( -- returns the name of the county associated with a US zip code.
- Date Patterns -- control how dates are displayed or converted to text.
- date( -- converts text into a number representing a date.
- datepattern( -- converts a number representing a date into text. The function uses a pattern to control how the date is formatted (see Date Patterns).
- datevalue( -- converts integer values for year, month and day into a number representing a date.
- dayofweek( -- computes the day of the week, with Sunday being 0, Monday 1, etc.
- dayvalue( -- extracts the day from a date as a numeric value.
- degree -- tells Panorama that all angles input to and calculated in trigonometric functions are in degrees rather than radians.
- degrees2radians( -- converts an angle from degrees to radians.
- degreestoradians( -- converts an angle from degrees into radians
- eulersconstant( -- returns the value of Euler's constant.
- expand -- reveals the next level of collapsed detail records associated with the currently active summary record.
- expandall -- reveals all collapsed detail records associated with the currently active summary record.
- firstdayofweek( -- returns the user's preference for first day of the week.
- fv( -- (short for *future value*) calculates the future value of an investment.
- groupdatepattern( -- converts a number representing a date into text in a special format for use with the summarytable( and crosstab( functions. The function uses a pattern to control how the date is formatted (see Date Patterns).
- groupdown -- divides the database into groups, with a summary record at the end of each group. The groups are arranged in descending order (high to low).
- groupup -- divides the database into groups, with a summary record at the end of each group. The groups are arranged in ascending order (low to high).
- info("angleunits") -- returns the current angular measurement units.
- info("collapsible") -- checks to see if the current record is collapsible.
- info("expandable") -- checks to see if the current record is expandable.
- latlongdistance( -- calculates the distance between two points on the earth (or any other sphere).
- log( -- computes the natural logarithm (base e ) of a value.
- log10( -- computes the common logarithm (base 10) of a value.
- mapurl( -- returns a URL to display a map location.
- maximum -- calculates the maximum and sub-maximums for the current field.
- minimum -- calculates the minimum and sub-minimums for the current field.
- month1st( -- computes the first day of a month.
- monthlength( -- computes the length (number of days) of a month.
- monthmath( -- takes a date and computes the date that is one or more months before or after the original date.
- monthvalue( -- extracts the month from a date as a numeric value.
- naturaldate( -- converts a number representing a date into text using "natural" formatting.
- nth( -- converts a number into an ordinal.
- openmapwindow -- opens a window displaying a map of a location.
- openwebmap -- opens a web browser window displaying a map of a location.
- pi( -- returns the value of pi .
- pmt( -- (short for *payment*) calculates the periodic payment required to pay off a loan.
- pv( -- (short for *present value*) calculates the present value of an income or debit stream of payments.
- quarter1st( -- computes the first day of a quarter.
- quartervalue( -- extracts the quarter from a date as a numeric value.
- radian -- tells Panorama that all angles in trigonometric functions should be calculated using radians rather than degrees.
- radians2degrees( -- converts an angle from radians to degrees.
- radianstodegrees( -- converts an angle from radians to degrees.
- regulardate( -- extracts a regular date (number of days from January 1, 4713 B.C.) from a superdate.
- removeallsummaries -- removes all summary records.
- removedetail -- removes data records from the current database, leaving only summary records. It can also delete low level summary records, leaving only higher levels.
- removesummaries -- removes summary records from the current database.
- scientificnotation( -- converts a number to text, formatted in scientific notation.
- selectzipdistancetool -- selects records near the current record, based on zip codes.
- sin( -- calculates the sine of an angle.
- state( -- returns the name of the state associated with a US zip code.
- stateabbreviations( -- returns a list of US state abbreviations.
- statelookup( -- converts a two letter abbreviation for a US state into the full state name.
- statename( -- converts a two letter abbreviation for a US state into the full state name.
- superdate( -- converts a regular date and a regular time into a superdate.
- superdatepattern( -- converts a number containing a superdate to text, allowing you to specify the patterns for both the date and the time conversion to text.
- superdatesecondsstr( -- converts a number containing a superdate to text, including the seconds.
- superdatestr( -- converts a number containing a superdate (date + time) to text.
- supernow( -- returns the number representing the current date and time as a superdate.
- tan( -- calculates the tangent of an angle.
- today( -- returns a number corresponding to today's date.
- total -- calculates totals and subtotals for the current field.
- uspssecondaryunits( -- returns a list of USPS (United States Postal Service) secondary suffix designation abbreviations.
- uspsstreetsuffixes( -- returns a list of USPS street suffix abbreviations.
- week1st( -- computes the first day of a week (Sunday).
- weekvalue( -- extracts the week from a date as a numeric value.
- year1st( -- computes the first day of a year.
- yearvalue( -- extracts the year from a date as a numeric value.
- zipdistance( -- calculates the distance between two zip codes.
- ziplatitude( -- returns the latitude of a US zip code.
- ziplongitude( -- returns the longitude of a US zip code.

History

Version | Status | Notes
10.0 | No Change | Carried over from Panorama.