Float

Function

Syntax

Turns a value into a number. Text that holds a number, such as "2.5", gives that number with its decimals.

Float(<value>)

Parts

<value>A number or a text. Text may have spaces around it and may use 1e3 or 0x10 notation.

Returns

The number. NaN when the text holds anything besides one number ("2.5x", "2,5", "abc"). An empty text gives 0, TRUE gives 1.

Good to know

  • It is not needed for division: / already keeps the decimals, and 7 / 2 is 3.5.
  • Unlike ValFloat(), which reads the number at the start of the text and gives 0 when there is none, Float gives NaN as soon as the text holds anything else. Test the result before using it.
  • Storing the result in an AS integer variable still drops the decimals: the variable's type wins.

Example

text$ = "2.5"Console(Str(Float(text$) * 2))   ' 5Console(Str(Float("abc")))   ' NaN
In the manual : Constants and operators

Commands that go with it

See also