]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/numformatter.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/numformatter.h
3 // Purpose: interface to wxNumberFormatter
4 // Author: Fulvio Senore, Vadim Zeitlin
5 // Licence: wxWindows licence
6 /////////////////////////////////////////////////////////////////////////////
9 @class wxNumberFormatter
11 Helper class for formatting and parsing numbers with thousands separators.
13 This class contains only static functions, so users must not create instances
14 but directly call the member functions.
20 class wxNumberFormatter
24 Bit masks used with ToString().
29 This flag can be used to indicate absence of any other flags below.
34 If this flag is given, thousands separators will be inserted in the
35 number string representation as defined by the current locale.
37 Style_WithThousandsSep
= 0x01,
40 If this flag is given, trailing zeroes in a floating point number
41 string representation will be omitted.
43 If the number is actually integer, the decimal separator will be
44 omitted as well. To give an example, formatting the number @c 1.23
45 with precision 5 will normally yield "1.23000" but with this flag
46 it would return "1.23". And formatting @c 123 with this flag will
47 return just "123" for any precision.
49 This flag can't be used with ToString() overload taking the integer
52 Style_NoTrailingZeroes
= 0x02
56 Returns string representation of an integer number.
58 By default, the string will use thousands separators if appropriate for
59 the current locale. This can be avoided by passing Style_None as @a
60 flags in which case the call to the function has exactly the same
61 effect as <code>wxString::Format("%ld", val)</code>.
63 Notice that calling ToString() with a value of type @c int and
64 non-default flags results in ambiguity between this overload and the
65 one below. To resolve it, you need to cast the value to @c long.
68 The variable to convert to a string.
70 Combination of values from the Style enumeration (except for
71 Style_NoTrailingZeroes which can't be used with this overload).
73 static wxString
ToString(long val
, int flags
= Style_WithThousandsSep
);
76 Returns string representation of a floating point number.
79 The variable to convert to a string.
81 Number of decimals to write in formatted string.
83 Combination of values from the Style enumeration.
86 ToString(double val
, int precision
, int flags
= Style_WithThousandsSep
);
90 Parse a string representation of a number possibly including thousands
93 These functions parse number representation in the current locale. On
94 success they return @true and store the result at the location pointed
95 to by @a val (which can't be @NULL), otherwise @false is returned.
97 @see wxString::ToLong(), wxString::ToDouble()
100 static bool FromString(wxString s
, long *val
);
101 static bool FromString(wxString s
, double *val
);
105 Get the decimal separator for the current locale.
107 Decimal separators is always defined and we fall back to returning '.'
110 static wxChar
GetDecimalSeparator();
113 Get the thousands separator if grouping of the digits is used by the
116 The value returned in @a sep should be only used if the function
117 returns @true, otherwise no thousands separator should be used at all.
120 Points to the variable receiving the thousands separator character
121 if it is used by the current locale. May be @NULL if only the
122 function return value is needed.
124 static bool GetThousandsSeparatorIfUsed(wxChar
*sep
);