wxWidgets: wxNumberFormatter Class Reference

| Version: 3.1.5

Loading...
Searching...
No Matches
Public Types | Static Public Member Functions | List of all members
wxNumberFormatter Class Reference

`#include </cygdrive/c/Users/Hamis/Cygwin-packaging/wxWidgets3.1/wxWidgets3.1-3.1.5-3.x86_64/src/wxWidgets-3.1.5/interface/wx/numformatter.h>`

## Detailed Description

Helper class for formatting and parsing numbers with thousands separators.

This class contains only static functions, so users must not create instances but directly call the member functions.

Since
  2.9.2

##

Library: wxBase

## Public Types
enum | Style { Style_None = 0x00 , Style_WithThousandsSep = 0x01 , Style_NoTrailingZeroes = 0x02 }
| Bit masks used with ToString(). More...

## Static Public Member Functions
static wxString | ToString (long val, int flags=Style_WithThousandsSep)
| Returns string representation of an integer number.
static wxString | ToString (long long val, int flags=Style_WithThousandsSep)
static wxString | ToString (unsigned long long val, int flags=Style_WithThousandsSep)
static wxString | ToString (double val, int precision, int flags=Style_WithThousandsSep)
| Returns string representation of a floating point number.
static bool | FromString (wxString s, long *val)
| Parse a string representation of a number possibly including thousands separators.
static bool | FromString (wxString s, long long *val)
static bool | FromString (wxString s, unsigned long long *val)
static bool | FromString (wxString s, double *val)
static wxChar | GetDecimalSeparator ()
| Get the decimal separator for the current locale.
static bool | GetThousandsSeparatorIfUsed (wxChar *sep)
| Get the thousands separator if grouping of the digits is used by the current locale.

## Member Enumeration Documentation

## ◆ Style

enum wxNumberFormatter::Style

Bit masks used with ToString().

Enumerator
Style_None | This flag can be used to indicate absence of any other flags below.
Style_WithThousandsSep | If this flag is given, thousands separators will be inserted in the number string representation as defined by the current locale.
Style_NoTrailingZeroes | If this flag is given, trailing zeroes in a floating point number string representation will be omitted. If the number is actually integer, the decimal separator will be omitted as well. To give an example, formatting the number `1.23` with precision 5 will normally yield "1.23000" but with this flag it would return "1.23". And formatting `123` with this flag will return just "123" for any precision. This flag can't be used with ToString() overload taking the integer value.

## Member Function Documentation

## ◆ FromString() [1/4]

bool wxNumberFormatter::FromString | ( | wxString | s,
|  | double * | val )
| static

## ◆ FromString() [2/4]

bool wxNumberFormatter::FromString | ( | wxString | s,
|  | long * | val )
| static

Parse a string representation of a number possibly including thousands separators.

These functions parse number representation in the current locale. On success they return true and store the result at the location pointed to by val (which can't be NULL), otherwise false is returned.

Note that the overload taking unsigned long long value is only available since wxWidgets 3.1.5. Also, unlike wxString::ToULongLong() and the standard functions such as `strtoul()`, this overload does not accept, i.e. returns false, for the strings starting with the minus sign.

See also
  wxString::ToLong(), wxString::ToDouble()

## ◆ FromString() [3/4]

bool wxNumberFormatter::FromString | ( | wxString | s,
|  | long long * | val )
| static

## ◆ FromString() [4/4]

bool wxNumberFormatter::FromString | ( | wxString | s,
|  | unsigned long long * | val )
| static

## ◆ GetDecimalSeparator()

wxChar wxNumberFormatter::GetDecimalSeparator | ( |  | ) |
| static

Get the decimal separator for the current locale.

Decimal separators is always defined and we fall back to returning '.' in case of an error.

## ◆ GetThousandsSeparatorIfUsed()

bool wxNumberFormatter::GetThousandsSeparatorIfUsed | ( | wxChar * | sep | ) |
| static

Get the thousands separator if grouping of the digits is used by the current locale.

The value returned in sep should be only used if the function returns true, otherwise no thousands separator should be used at all.

Parameters

  sep | Points to the variable receiving the thousands separator character if it is used by the current locale. May be NULL if only the function return value is needed.

## ◆ ToString() [1/4]

wxString wxNumberFormatter::ToString | ( | double | val,
|  | int | precision,
|  | int | flags = Style_WithThousandsSep )
| static

Returns string representation of a floating point number.

Parameters

  val | The variable to convert to a string.
  precision | Number of decimals to write in formatted string.
  flags | Combination of values from the Style enumeration.

## ◆ ToString() [2/4]

wxString wxNumberFormatter::ToString | ( | long long | val,
|  | int | flags = Style_WithThousandsSep )
| static

## ◆ ToString() [3/4]

wxString wxNumberFormatter::ToString | ( | long | val,
|  | int | flags = Style_WithThousandsSep )
| static

Returns string representation of an integer number.

By default, the string will use thousands separators if appropriate for the current locale. This can be avoided by passing Style_None as flags in which case the call to the function has exactly the same effect as `wxString::Format("%ld", val)`.

Notice that calling ToString() with a value of type `int` and non-default flags results in ambiguity between this overload and the one below. To resolve it, you need to cast the value to `long`.

Parameters

  val | The variable to convert to a string.
  flags | Combination of values from the Style enumeration (except for Style_NoTrailingZeroes which can't be used with this overload).

## ◆ ToString() [4/4]

wxString wxNumberFormatter::ToString | ( | unsigned long long | val,
|  | int | flags = Style_WithThousandsSep )
| static