ScanSkill

float

float() function returns an expression(or value) converted into a floating-point number.

Syntax

float(number)

Here,

  • value: Optional. Can be of string, int, float, or long type.

Note: Float accepts the strings nan, inf, and -inf for NaN and positive or negative infinity. The case and a leading + are ignored as well as a leading - is ignored for NaN. Float always represents NaN and infinity as nan, inf, or -inf.

Examples

  • String and numeric type
>>> float(1)
1.0
>>> float(1.34)
1.34
>>> float('2')
2.0
>>> float('-2')
-2.0
>>> float('-2.313123')
-2.313123
  • NaN and infinity type
>>> float('+nan')
nan
>>> float('-infinity')
-inf