Converts $string-var (a string) to a 32 bit floating point value. The data type float corresponds to the IEEE single-precision 32-bit floating point type (IEEE Std 754-1985).
If the value of $string-var is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.
xs:float(xs:string $string-var) —> xs:float
Represents the string to convert to a float. |
Returns the floating point value of $string-var.
Invoking float("1.1")returns the floating point value of 1.1 as shown in the following example query:
<float>{xs:float("1.1")}</float>
The preceding query generates the following result:
<float>1.1</float>
Invoking float("-104.345e2")returns the floating point value of -10434.5 as shown in the following example query:
<float>{xs:float("-104.345e2")}</float>
The preceding query generates the following error:
<float>-10434.5</float>
The string: NaN (Not a Number) is a legal argument, as shown in the following example query:
<float>{xs:float("NaN")}</float>
The preceding query generates the following result:
<float>NaN</float>
The strings: INF (positive infinity) and -INF (negative infinity) are legal arguments as shown in the following example query:
<infinity> <positive>{xs:float("INF")}</positive> <negative>{xs:float("-INF")}</negative> </infinity>
The preceding query generates the following result:
<infinity> <positive>Infinity</positive> <negative>-Infinity</negative> </infinity>
Invoking float("10.1e2.1") outputs an error because 2.1 is not an integer. For example, the following example query:
<float>{xs:float("10.1e2.1")}</float>
Error occurred while executing XQuery: Could not cast "10.1e2.1" to type [float@http://www.w3.org/2001/XMLSchema]
Invoking float(()) returns the empty sequence. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.
For example, the following example query:
<float>{xs:float(())}</float>
The preceding query generates the following result:
<float/>
W3C float data type description