Public Types | Public Member Functions

# wxFloatingPointValidator< T > Class Template Reference
[Validators]

`#include <wx/valnum.h>`

Inheritance diagram for wxFloatingPointValidator< T >:
[legend]

## Detailed Description

### template<typename T>
class wxFloatingPointValidator< T >

Validator for text entries used for floating point numbers entry.

This validator can be used with wxTextCtrl or wxComboBox (and potentially any other class implementing wxTextEntry interface) to check that only valid floating point values can be entered into them. Currently only fixed format is supported on input, i.e. scientific format with mantissa and exponent is not supported.

This template class can be instantiated for either `float` or `double`, `long double` values are not currently supported.

Similarly to wxIntegerValidator<>, the range for the accepted values is by default set appropriately for the type. Additionally, this validator allows to specify the maximum number of digits that can be entered after the decimal separator. By default this is also set appropriately for the type used, e.g. 6 for `float` and 15 for `double` on a typical IEEE-754-based implementation. As with the range, the precision can be restricted after the validator creation if necessary.

A simple example of using this class:

            class MyDialog : public wxDialog
            {
            public:
                MyDialog()
                {
                    ...
                    // Allow floating point numbers from 0 to 100 with 2 decimal
                    // digits only and handle empty string as 0 by default.
                    wxFloatingPointValidator<float>
                        val(2, &m_value, wxNUM_VAL_ZERO_AS_BLANK);
                    val.SetRange(0, 100);

                    // Associate it with the text control:
                    new wxTextCtrl(this, ..., val);
                }

            private:
                float m_value;
            };

For more information, please see wxValidator Overview.

##

Library: wxCore
Category: Validators

See also:
  wxValidator Overview, wxValidator, wxGenericValidator, wxTextValidator, wxMakeIntegerValidator()

Since:
  2.9.2

## Public Types
typedef T | ValueType
| Type of the values this validator is used with.
## Public Member Functions
void | SetPrecision (unsigned precision)
| Set precision.
| wxFloatingPointValidator (ValueType *value=NULL, int style=wxNUM_VAL_DEFAULT)
| Validator constructor.
| wxFloatingPointValidator (int precision, ValueType *value=NULL, int style=wxNUM_VAL_DEFAULT)
| Validator constructor.

List of all members.

## Member Typedef Documentation

template<typename T>

typedef T wxFloatingPointValidator< T >::ValueType

Type of the values this validator is used with.

Reimplemented from wxNumValidator< T >.

## Constructor & Destructor Documentation

template<typename T>

wxFloatingPointValidator< T >::wxFloatingPointValidator | ( | ValueType * | value = `NULL`,
|  | int | style = `wxNUM_VAL_DEFAULT` |
| ) |  |  |

Validator constructor.

Parameters:

  | value | A pointer to the variable associated with the validator. If non NULL, this variable should have a lifetime equal to or longer than the validator lifetime (which is usually determined by the lifetime of the window).
  | style | A combination of wxNumValidatorStyle enum values.
  | precision | The number of decimal digits after the decimal separator to show and accept.

template<typename T>

wxFloatingPointValidator< T >::wxFloatingPointValidator | ( | int | precision,
|  | ValueType * | value = `NULL`,
|  | int | style = `wxNUM_VAL_DEFAULT` |
| ) |  |  |

Validator constructor.

Parameters:

  | value | A pointer to the variable associated with the validator. If non NULL, this variable should have a lifetime equal to or longer than the validator lifetime (which is usually determined by the lifetime of the window).
  | style | A combination of wxNumValidatorStyle enum values.
  | precision | The number of decimal digits after the decimal separator to show and accept.

## Member Function Documentation

template<typename T>

void wxFloatingPointValidator< T >::SetPrecision | ( | unsigned | precision | ) |

Set precision.

Precision is the number of digits shown (and accepted on input) after the decimal point. By default this is set to the maximal precision supported by the type handled by the validator in its constructor.

|  | [ top ]