Number
A number type can be defined with the members such as type
, default
, choices
, min
, max
, multipleOf
, divisibleBy
, optional
and null
. Schema of the number TypeDef should be written as,
TypeDefs Schema
The TypeDef schema ensures the validity of number
MemberDefs.
type
The first member of the typedef is type
. The number can be of type number
or its derived types i.e int
, int16
, int32
, byte
. Here the next snippet shows how the number
type and its derived types can be defined.
default
The second member in the number
typedef is default
. Here is how the default values can be defined for a number.
Rules for default:
The default value is applicable only if no other value is provided for the key.
If for a key, null is set to true then it must be replaced by its default value.
The default value when set must match with the data type of a key.
choices
The choices
can be added to member variables in numbers so that the input values are restricted to the fixed set of available choices. Choices must be an array of numbers. The code snippet shows how to add choices.
max
The max
represents the maximum value of a key, that must be a number. The numeric instance max
is valid only if its value is less than or equal to the value of the max
. Here is the snippet that shows how to set max
value for a number.
min
The min
represents the minimum value of a key, that must be a number. The numeric instance min
is valid only if its value is greater than or equal to the value of the min
. Here is the snippet that shows how to set min
value for a number.
multipleOf
The multipleOf
is used to restrict the value to multiples of a given number. The Value of multipleOf
must be a positive integer. The code snippet shows how to restrict the input value to the multiple of the desired number.
divisibleBy
The divisibleBy
is used to restrict the value to divisible by of a given number as shown below.
optional
The member of a number type can be set to optional
. Here is the code snippet that demonstrates how a number can be set to optional.
null
A number when set to null: true
will accept null values. The snippet below shows how to set a nullable number.
Examples
Here are some of the examples that demonstrate how to define number member definition.
Last updated