Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

look::LookFloat Class Reference

Class representing a floating point value. More...

#include <lkfloat.h>

Inheritance diagram for look::LookFloat::

look::LookTypeBase List of all members.

Public Methods

 LookFloat (double theValue=0.0)
 Constructor.

 ~LookFloat (void)
 Destructor.

 LookFloat (const LookFloat &theOther)
 Copy constructor.

LookFloat& operator= (const LookFloat &theOther)
 Assignment.

LookTypeBaseGetNewCopy (void) const
 Get a new copy. More...

long GetTypeID (void) const
 Get Type ID. More...

 operator double (void) const
 Cast to double.

bool Set (const LookString &theString)
 Set from a string. More...

LookString GetString (int aPrecision) const
 Convert to a string. More...

LookString GetStrippedString (int aPrecision) const
 Convert to a string, no trailing 0 or . More...

LookFloat& operator+= (const LookFloat &)
 Addition.

LookFloat& operator-= (const LookFloat &)
 Subtraction.

LookFloat operator+ (const LookFloat &) const
 Addition.

LookFloat operator- (const LookFloat &) const
 Subtraction.

long GetRoundedInteger (void) const
 Get value rounded to nearest long. More...

bool LessEqual (const LookFloat &theOtherFloat, int thePrecision) const
 Less than or equal within a precision. More...

bool LessThan (const LookFloat &theOtherFloat, int thePrecision) const
 Less than within a precision. More...

bool IsEqual (const LookFloat &theOtherFloat, int thePrecision) const
 Equal within a precision. More...

bool IsZero (int thePrecision) const
 Is zero within a precision. More...


Protected Attributes

double itsValue
 Its value.


Detailed Description

Class representing a floating point value.

It has some rounding abilities. Internally it uses a double.


Member Function Documentation

LookTypeBase * look::LookFloat::GetNewCopy ( void ) const [virtual]
 

Get a new copy.

Virtual copy constructor, aka clone.

Returns:
A new copy of this. (You are responsible for deleting it).

Reimplemented from look::LookTypeBase.

long look::LookFloat::GetRoundedInteger ( void ) const
 

Get value rounded to nearest long.

(See LookMoney for a short discussion on adding very small numbers to fix rounding at the 0.5 mark - you will have to do this yourself)

Returns:
Nearest long

LookString look::LookFloat::GetString ( int aPrecision ) const
 

Convert to a string.

The precision is the number of decimal places to include. It can be negative. The value is rounded to the nearest value. Trailing zeros are included.

(See LookMoney for a short discussion on adding very small numbers to fix rounding at the 0.5 mark - you will have to do this yourself)

Eg 12345.67

  • 4 gives 12345.6700
  • 1 gives 12345.7
  • 0 gives 12346
  • -2 gives 12300
Parameters:
aPrecision   The precision.
Returns:
The string

LookString look::LookFloat::GetStrippedString ( int aPrecision ) const
 

Convert to a string, no trailing 0 or .

The precision is the number of decimal places to include. It can be negative. The value is rounded to the nearest value. Trailing zeros and decimal points are not included.

Eg 12345.98

  • 4 gives 12345.98
  • 1 gives 12346
  • 0 gives 12346
  • -2 gives 12300
Parameters:
aPrecision   The precision.
Returns:
The string

long look::LookFloat::GetTypeID ( void ) const [virtual]
 

Get Type ID.

Pseudo-rtti, or isA.

Returns:
LookFloatID

Reimplemented from look::LookTypeBase.

bool look::LookFloat::IsEqual ( const LookFloat & theOtherFloat,
int thePrecision ) const
 

Equal within a precision.

See LessEqual()

bool look::LookFloat::IsZero ( int thePrecision ) const
 

Is zero within a precision.

Like Equal(), except theOther is 0. Eg 0.0001 is zero for precision <= 3.

Parameters:
thePrecision   Precision
Returns:
true if it is zero

bool look::LookFloat::LessEqual ( const LookFloat & theOtherFloat,
int thePrecision ) const
 

Less than or equal within a precision.

Comparison ops with floating points sometimes don't work very well, due to precision issues.

This is an attempt to get round this.

Eg my value 123.4567, other 123.4566

me.LessEqual( other, 4 ) = false. me.LessEqual( other, 3 ) = true.

Parameters:
theOtherFloat   The other float to compare with
thePrecision   The precision with which to compare
Returns:
Obvious

bool look::LookFloat::LessThan ( const LookFloat & theOtherFloat,
int thePrecision ) const
 

Less than within a precision.

See LessEqual()

bool look::LookFloat::Set ( const LookString & theString )
 

Set from a string.

The string must be in the form xxxx, -xxxx, -xxx.xx or xxx.xx. Ie minus at front if present, only one decimal point.

If any other characters are present, false will be returned, but its value will still be set to what it would have been if all the invalid characters weren't present.

Parameters:
theString   The string to convert
Returns:
true for success, false otherwise


The documentation for this class was generated from the following files:
Generated at Thu Jan 17 12:53:08 2002 for liblookdb by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001