All Classes Namespaces Functions Variables Groups Pages
<float> Class Reference

Methods in this pseudo-class can be executed on floating-point values. More...

Inheritance diagram for Qore::<float>:
[legend]

## Public Member Functions

string | format (string fmt)
| Returns a string of a formatted number according to a format string.
bool | intp ()
| Returns True because float values can be converted to integers.
int | sign ()
| Returns -1 if the number is negative, 0 if it is zero, or 1 if it is positive.
bool | strp ()
| Returns True because float values can be converted to strings.
int | typeCode ()
| Returns Qore::NT_FLOAT.
bool | val ()
| Returns True if the float is non-zero, False if zero.
Public Member Functions inherited from <value>
bool | callp ()
| Returns False; this method is reimplemented in other types and will return True if the given expression is a callable value (ie closures or call references)
bool | empty ()
| Returns True; this method will be reimplemented in container types where it may return False.
bool | intp ()
| Returns False; this method is reimplemented in other types and will return True if the given expression can be converted to an integer.
AbstractIterator | iterator ()
| Returns an iterator object for the value; the default iterator object returned is SingleValueIterator.
int | lsize ()
| Returns 1; the return value of this method should give the list size of the value, which is normally 1 for non-lists (except for NOTHING where the size will be 0) and the number of the elements in the list for lists; this method will be reimplemented in other types where it may return other values.
int | size ()
| Returns zero; this method will be reimplemented in container types where it may return a non-zero value.
bool | strp ()
| Returns False; this method is reimplemented in other types and will return True if the given expression can be converted to a string.
bool | toBool ()
| Returns the boolean representation of the value; the default is False.
float | toFloat ()
| Returns the floating-point representation of the value; the default is 0.0.
int | toInt ()
| Returns the integer representation of the value; the default is 0.
string | toString ()
| Returns the string representation of the value; the default is an empty string.
string | type ()
| Returns the string type for the value.
int | typeCode ()
| Returns the type code for the value.
bool | val ()
| Returns False; this method is reimplemented in other types and will return True if the given expression has a value.

## Detailed Description

Methods in this pseudo-class can be executed on floating-point values.

## Member Function Documentation

string <float>::format | ( | string | fmt | ) |

Returns a string of a formatted number according to a format string.

Code Flags:
  CONSTANT

Parameters

  fmt

  the format string has the following format:
  <thousands_separator>`[`<decimal_separator><decimals>`]`
  where:
  - thousands_separator and decimal_separator are single ASCII characters defining the thousands and decimal separator characters respectively, and
  - decimals is a single digit defining how may decimals should appear after the decimal point

Returns
  a string of a formatted number according to a format string; if the format string does not follow the given format, then an empty string is returned

Example:
  my float $f = -48392093894.2349;
  my string $nstr = $f.format(".,3"); # returns "-48.392.093.894,235"

Note
  equivalent to format_number(string, softfloat)

Since
  Qore 0.8.6

bool <float>::intp | ( |  | ) |

Returns True because float values can be converted to integers.

Returns
  True because float values can be converted to integers

Code Flags:
  CONSTANT

Example:
  if ($n.intp())
  printf("%y: can be converted to an integer: %d\n", $n, int($n));

int <float>::sign | ( |  | ) |

Returns -1 if the number is negative, 0 if it is zero, or 1 if it is positive.

Returns
  -1 if the number is negative, 0 if it is zero, or 1 if it is positive

Code Flags:
  CONSTANT

Example:
  printf("sign: %d\n", $f.sign());

Since
  Qore 0.8.6

bool <float>::strp | ( |  | ) |

Returns True because float values can be converted to strings.

Returns
  True because float values can be converted to strings

Code Flags:
  CONSTANT

Example:
  if ($n.strp())
  printf("%y: can be converted to a string: '%s'\n", $n, string($n));

int <float>::typeCode | ( |  | ) |

Returns Qore::NT_FLOAT.

Returns
  Qore::NT_FLOAT

Code Flags:
  CONSTANT

Example:
  switch ($f.typeCode()) {
  case NT_FLOAT:
  printf("%y: is a float\n", $f);
  break;
  }

bool <float>::val | ( |  | ) |

Returns True if the float is non-zero, False if zero.

Returns
  True if the float is non-zero, False if zero

Code Flags:
  CONSTANT

Example:
  my bool $b = $f.val();

See Also
  - %perl-bool-eval
  - %strict-bool-eval