Number type

In AskiaScript, a number type variable contains a numeric value. This value can be an integer or a double.

To create a number type variable, simply assign a number to a variable. To create a double, a decimal value is required; the decimal separator is the dot, or period (.). Examples:

dim my_integer = 1

dim my_negative = -3

dim my_double = 0.1

dim my_shorthand_double = .3 ' => same as 0.3

 

In this topic:

Methods

ToInt()

Converts a number (double) to integer. This method will not round the number.

Returns a Number.

Examples
dim counter = 1.2
counter.ToInt() ' => 1

 

dim i = 1.5
i.ToInt() ' => 1

↑ Top of page ↑

Round([decimal])

Rounds a double.

Returns a Number.

Parameters

decimal [Optional] {Number}

Number of decimals to keep. If this parameter is not specified, no decimal will be returned (same as Round(0)).

Examples
dim counter = 1.2
counter.Round() ' => 1

 

dim i = 1.5
i.Round() ' => 2

 

dim j = 1.55555
j.Round(2) ' => 1.56

 

dim k = 1
k.Round(2) ' => 1

↑ Top of page ↑

Ceil([decimal])

Returns the next highest value by rounding up a value.

Returns a Number.

Parameters

decimal [Optional] {Number}

Number of decimals to keep. If this parameter is not specified, no decimal will be returned (same as Round(0))).

Examples
dim counter = 1.2
counter.Ceil() ' => 2
dim i = -3.14
i.Ceil() ' => -3
dim j = 1.5222
j.Ceil(2) ' => 1.53

↑ Top of page ↑

Floor([decimal])

Returns the next lowest value by rounding down a value.

Returns a Number.

Parameters

decimal [Optional] {Number}

Number of decimals to keep If this parameter is not specified, no decimal will be returned (same as Round(0)).

Examples

dim counter = 1.7
counter.Floor() ' => 1
dim i = -3.84
i.Floor() ' => -4
dim j = 1.5777
j.Floor(2) ' => 1.57

↑ Top of page ↑

Abs()

Returns the absolute part of a number (positive value).

Returns a Number.

Examples
dim counter = -3
counter.Abs() ' => 3
dim i = -1.5
i.Abs() ' => 1.5

↑ Top of page ↑

Pow(power)

Returns the power of a value.

Returns a Number.

Parameters

power [required] {Number}: The power to be applied.

Examples
dim counter = 2
counter.Pow(3) ' => 8
'Same as (2 * 2 * 2)

↑ Top of page ↑

ToSeconds()

Converts the specified number of days to seconds, using the following formula:

number * (24 * 3600)

Returns a Number.

Examples

dim i = 2
i.ToSeconds() ' => 172800

(Date1 - Date2).ToSeconds()
' => (Date1 - Date2) * (24 * 3600)

↑ Top of page ↑

ToMinutes()

Converts the specified number of days to minutes, using the following formula:

number * (24 * 60)

Returns a Number.

Examples

dim i = 2
i.ToMinutes() ' => 2880

(Date1 - Date2).ToMinutes()
' => (Date1 - Date2) * (24 * 60)

↑ Top of page ↑

ToHours()

Converts the specified number of days to hours, using the following formula:

number * (24)

Returns a Number.

Examples
dim i = 2
i.ToHours() ' => 48
(Date1 - Date2).ToHours() 
' => (Date1 - Date2) * (24)

↑ Top of page ↑

ToDays()

Converts the specified number of days to days,using the following formula:

(number)

In other words, this function returns the number passed to it.

Returns a Number.

Examples
dim i = 2
i.ToDays() ' => 2
(Date1 - Date2).ToDays()
' => The number of days

↑ Top of page ↑

Format(format [, decimalSep [, thousandSep])

Formats a number to a string, using the format parameter.

Parameters

See also: Number Formatting.

Examples

dim i = 3456.7
i.Format("00000.00")
' => "03456.70" or "03456,70"
' depending on the regional settings
dim i = 3456.7
i.Format("#.##") 
' =>"3456.7" or "3456,7" 
' depending on the regional settings
dim i = 3456.7
i.Format("#,##0.00")  
'=>  "3,456.70" or "3 456,70" or "3.456,70" 
'  depending on the regional settings
dim i = 3456.7
i.Format("$#,##0.00") 
'=> "$3,456.70" or "$3 456,70" or "$3.456,70" 
' depending on the regional settings
dim i = 0.1
i.Format("#.##") ' => ".1" or ",1" 
' depending on the regional settings
dim i = 0.1
i.Format("0.##") ' => "0.1" or "0,1" 
' depending on the regional settings
dim i = 0.1
i.Format("0.00") ' => "0.10" or "0,10" 
' depending on the regional settings
dim i = 123456.78
i.Format("#,##0.00", ",", ".") ' => "123.456,78" 
i.Format("#,##0.00", ".", ",") ' => "123,456.78" 
i.Format("#,##0.00", "#", "@") ' => "123@456#78" 
i.Format("#.##", ",") ' => "123456,78" 
i.Format("#.##", ".") ' => "123456.78" 

↑ Top of page ↑

ToString()

Converts a number to a string, using the regional settings context (from the language of respondent or the current machine) to determine the decimal separator.

Returns a String.

If you want to enforce/fixed the decimal separator, you should use the format method where possible.
Examples
dim counter = 1.9
counter.ToString() ' => "1.9" or "1,9" 
' depending on the regional settings

↑ Top of page ↑

TypeOf()

Always returns the string "number".

Returns a String.

Example

dim i = 2
i.TypeOf() ' => "number"

↑ Top of page ↑

Operators

Name Symbol / Expression Description Example
Addition +

Mathematical addition between numbers.

Returns a number.

dim i = 1.9
dim j = 2
i + j ' => 3.9
Subtraction -

Mathematical subtraction between numbers.

Returns a number.

dim i = 2
dim j = 1.1
i - j ' => 0.9
Multiplication *

Mathematical multiplication between numbers.

Returns a number.

dim i = 4
dim j = 2
i * j ' => 8
Division / Mathematical division between numbers
Returns a number
Raise an exception when trying to divide by zero
dim i = 4
dim j = 2
i / j ' => 2
Equal =

Tests whether two numbers are equal.

Returns a boolean.

To use this operator to perform a comparison, the condition should be between brackets, or else it will be considered as an assignment operator
dim i = 4
(i = 4) ' => True
(i = 2) ' => False
Different <>

Tests whether two numbers are not equal.

Returns a boolean.

dim i = 4
i <> 5 ' => True
i <> 4 ' => False
Less than <

Tests the relative values of two numbers.

Returns a boolean.

dim i = 4
i < 6 ' => True
i < 4 ' => False
Less or equal than <=

Tests the relative values of two numbers.

Returns a boolean.

dim i = 4
i <= 4 ' => True
i <= 3 ' => False
Greater than >

Tests the relative values of two numbers.

Returns a boolean.

dim i = 4
i > 2 ' => True
i > 4 ' => False
Greater or equal than >=

Tests the relative values of two numbers.

Returns a boolean.

dim i = 4
i >= 4 ' => True
i >= 5 ' => False
Modulo Mod

Mathematical division's modulo between numbers.

Returns a number.

dim i = 15
dim j = 2
i mod j ' => 1
'
dim c = 11
dim d = 3
c mod d ' => 2
At least one Has

Tests whether a number is contained in an array.

Returns a boolean.

dim i = 3
i Has {1;3;5} ' => True
i Has {1;5;7} ' => False
'
dim c = 3
dim d = {1;3;5}
c Has d ' => True
None HasNone

Tests whether a number is NOT contained in an array.

Returns a boolean.

dim i = 3
i HasNone {1;5;7} ' => True
i HasNone {1;3;5} ' => False
'
dim c = 3
dim d = {1;5;7}
c HasNone d ' => True

 

↑ Top of page ↑

DK value

Warning: backwards compatability
AskiaScript 1.0 recognised DK as a True value, so in that version of AskiaScript, DK and True ' => True and DK or False ' => True. However, AskiaScript 2.0 now recognises DK as a False value, so these two examples produce False. Therefore, please be careful if you have used this kind of comparison in your previous questionnaires.

 

The keyword DK for "Don't know" is a special numeric value against which you can test the validity of a numeric value. If the value to test is not a specific or valid number, then it is considered equal to DK.

AskiaScript allows you to do operations/comparisons against the DK keyword. The rule is simple: whatever operation you do with DK returns DK.

Operators
Name Symbol / Expression Description Example
Addition +

Mathematical addition between numbers.

Always returns DK.

DK + 3 ' => DK
DK + DK ' => DK
Subtraction -

Mathematical division between numbers.

Always returns DK.

DK - 3 ' => DK
3 - DK ' => DK
DK - DK ' => DK
Multiplication *

Mathematical multiplication between numbers.

Always returns DK.

DK * 3 ' => DK
DK * DK ' => DK
Division /

Mathematical division between numbers.

Always returns DK.

DK / 3 ' => DK
DK / DK ' => DK
Equal =

Tests whether two values are equal.

Returns a boolean.

To use it for comparison, the condition should be between brackets, or else it will be consider as an assignment operator.

dim wrongNumber = ("NotANumber").ToNumber()
(wrongNumber = DK) ' => True
dim rightNumber = ("12.16").ToNumber()
(rightNumber = DK) ' => False
dim text = "Hello world" 
(text.IndexOf("Hi") = DK) ' => True (not found)
(text.IndexOf("Hello") = DK) ' => False
(DK = 0) ' => False
(DK = DK) ' => True
Different <>

Tests whether two values are not equal.

Returns a boolean.

dim wrongNumber = ("NotANumber").ToNumber()
(wrongNumber <> DK) ' => False
dim rightNumber = ("12.16").ToNumber()
(rightNumber <> DK) ' => True
dim text = "Hello world" 
(text.IndexOf("Hi") <> DK) ' => False (not found)
(text.IndexOf("Hello") <> DK) ' => True
(DK <> 0) ' => True
(DK <> DK) ' => False
Less than <

Tests the relative values of two numbers.

Returns a boolean.

Note: The DK value behaves like an -INFINITY value in this case, so is always less than any given value.
dim number = 12
number < DK ' => False
DK < number ' => True
0 < DK  ' => False
DK < 0  ' => True
Less or equal than <=

Tests the relative values of two numbers.

Returns a boolean.

Note: The DK value behaves like an -INFINITY value in this case, so is always less than any given value.
dim number = 12
number <= DK ' => False
DK <= number ' => True
0 <= DK  ' => False
DK <= 0  ' => True
Greater than >

Tests the relative values of two numbers.

Returns a boolean.

Note: The DK value behaves like an -INFINITY value in this case, so is always less than any given value.
dim number = 12
number > DK ' => True
DK > number ' => False
0 > DK  ' => True
DK > 0  ' => False
Greater or equal than >=

Tests the relative values of two numbers.

Returns a boolean.

Note: The DK value behaves like an -INFINITY value in this case, so is always less than any given value.
dim number = 12
number >= DK ' => True
DK >= number ' => False
0 >= DK  ' => True
DK >= 0  ' => False
And And

Use this operator to define statements which are based on a specific combination of two or more variables.

With DK, this operator always returns false.

dim yes = true
(yes and DK) ' => false
dim no  = false
(no and DK) ' => false
Or Or

Use this operator to define statements which are based on two or more interchangeable/equivalent statements.

With DK, this operator always returns the value of the other statement.

dim yes = true
(yes or DK) ' => true
dim no  = false
(no or DK) ' => false

 

↑ Top of page ↑

Number Formatting

Characters Description
0 Represents a digit, with non-significant leading and trailing zeros.
# Represents a digit, without non-significant leading and trailing zeros.
. Indicates the decimal placeholder.
, Indicates the thousands separator placeholder.
[All other characters] Literal character; displayed as typed.

 

The decimal (.) and thousand separator (,) will be replaced by the decimal and the thousand separator from the regional settings context (from the respondent language or the regional settings of the current machine). For example:

' US people use the comma (,) as thousand separator and point (.) as decimal separator
' French people use space ( ) as thousand separator and coma (,) as decimal separator
dim i = 3456.7
i.Format("##,###.00") ' => "3 456,70" for French people
i.Format("##,###.00") ' => "3,456.70" for US people
' Using 3456.7
"00000" ' => "03456" 
"00000.0" ' => "03456.7" 
"00000.000" ' => "03456.700" 
"00,000" ' => "03,456" for US people, "03 456" for French people
"00.00" ' => "3456.70" for US people, "3456,70" for French people

"#" ' => "3456" 
"#.#" ' => "3456.7" for US people, "3456,7" for French people
"##,###.#" ' => "3,456.7" for US people, "3 456,7" for French people

"####0" ' => "3456" 
"####0.000" ' => "3456.700" for US people, "3456,700" for French people

"-$##,###.00 discount" '=> "-$3,456.70 discount" for US people, "-$3 456,70" for French people

 

↑ Top of page ↑

Create your own Knowledge Base