# 1 number

The tag <number> allows the creation of numeric data type of different sizes and precision. The package <number> provides functions for the localized conversion of string formats to numeric and vice versa.

Typically, the builder <number> will be used to generate numbers automatically, so the resulting type has an efficient form for the indicated data. By default, the integer values will use the integer type, while the floating point numbers will use the double type.

Optionally, the destination type can be indicated through the attribute type. In this cases, the resulting type will be indicated. For example:

Examples of construction of numeric types
<number>0</number> 0 integer java.lang.Integer
<number type='smallint'>0</number> 0 smallint java.lang.Short
<number>0.15</number> 0.15 double java.lang.Double
<number type='decimal'>0.15</number> 0.15 decimal java.math.BigDecimal
<number type='decimal' scale='3'>0.15</number> 0.150 decimal java.math.BigDecimal

#### Notas

The decimal type can accept the attribute scale to indicate the number of decimals.

<number    type='type'    scale='scale'>    <value /> !</number>

#### Exceptions

The function needs a entry value.

The scale is not well specified.

unsupported number type [...]

Type of numeric value not admitted.

unable to convert [...]

Impossible conversion.

#### Remarks

It is possible to obtain a numeric value of smallint, integer, long, float, double or decimal type. The type of numeric value obtained depends of the argument which receives the script-tag number or the specified attribute "type".If you want to indicate the amount of decimal which supports a numeric value, this should be of a type which supports decimals, otherwise it would not make sense. If the obtained number has an amount of decimals greater than the specified in the attribute "scale", these decimals will be rounded up.

Example

Define a numeric variable.

Copy
<xsql-script name='number_sample1'>
<body>
<set name='number'>
<number>13.4</number>
</set>
<println><number /></println>
<!-- The value shown is 13.4 -->
</body>
</xsql-script>
Example

Define a numeric variable with type and scale predefined.

Copy
<xsql-script name='number_sample2'>
<body>
<set name='number'>
<number type='decimal' scale='2'>13.4655</number>
</set>
<println><number /></println>
<!-- The value shown is 13.47, cuts and round up. -->

<set name='number'>
<number type='decimal' scale='2'>13.4635</number>
</set>
<println><number /></println>
<!-- The value shown is 13.46, cuts and round up. -->
</body>

</xsql-script>