Dec

Description

Converts the value of a string to a decimal.

Syntax

Dec ( string )

Argument

Description

string

The string you want returned as a decimal

Returns

Decimal. Returns the contents of string as a decimal if it succeeds and 0 if string is not a number.

Usage

The decimal datatype supports up to 28 digits.

You can also append the letter D in upper or lowercase to identify a number as a decimal constant in DataWindow expressions. For example, 2.0d and 123.456789012345678901D are treated as decimals.

Examples

Example 1

This expression returns the string 24.3 as a decimal datatype:

Dec("24.3")

Example 2

This expression for a computed field returns “Not a valid score” if the string in the score column does not contain a number. The expression checks whether the Dec function returns 0, which means it failed to convert the value:

If ( Dec(score) <> 0, score, "Not a valid score")

Example 3

This expression returns 0:

Dec("3ABC")    // 3ABC is not a number

Example 4

This validation rule checks that the value in the column the user entered is greater than 1999.99:

Dec(GetText()) > 1999.99

Example 5

This validation rule for the column named score insures that score contains a string:

Dec(score) <> 0

See also