]> git.saurik.com Git - wxWidgets.git/blame - include/wx/numformatter.h
Add wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG symbol.
[wxWidgets.git] / include / wx / numformatter.h
CommitLineData
6686fbad
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/numformatter.h
3// Purpose: wxNumberFormatter class
4// Author: Fulvio Senore, Vadim Zeitlin
5// Created: 2010-11-06
6// Copyright: (c) 2010 wxWidgets team
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10#ifndef _WX_NUMFORMATTER_H_
11#define _WX_NUMFORMATTER_H_
12
13#include "wx/string.h"
14
15// Helper class for formatting numbers with thousands separators which also
16// supports parsing the numbers formatted by it.
17class WXDLLIMPEXP_BASE wxNumberFormatter
18{
19public:
20 // Bit masks for ToString()
21 enum Style
22 {
23 Style_None = 0x00,
24 Style_WithThousandsSep = 0x01,
25 Style_NoTrailingZeroes = 0x02 // Only for floating point numbers
26 };
27
28 // Format a number as a string. By default, the thousands separator is
29 // used, specify Style_None to prevent this. For floating point numbers,
30 // precision can also be specified.
31 static wxString ToString(long val,
32 int style = Style_WithThousandsSep);
33
34 static wxString ToString(double val,
35 int precision,
36 int style = Style_WithThousandsSep);
37
38 // Parse a string representing a number, possibly with thousands separator.
39 //
40 // Return true on success and stores the result in the provided location
41 // which must be a valid non-NULL pointer.
42 static bool FromString(wxString s, long *val);
43 static bool FromString(wxString s, double *val);
44
45
46 // Get the decimal separator for the current locale. It is always defined
47 // and we fall back to returning '.' in case of an error.
48 static wxChar GetDecimalSeparator();
49
50 // Get the thousands separator if grouping of the digits is used by the
51 // current locale. The value returned in sep should be only used if the
52 // function returns true.
53 static bool GetThousandsSeparatorIfUsed(wxChar *sep);
54
55private:
56 // Add the thousands separators to a string representing a number without
57 // the separators. This is used by ToString(Style_WithThousandsSep).
58 static void AddThousandsSeparators(wxString& s);
59
60 // Remove trailing zeroes and, if there is nothing left after it, the
61 // decimal separator itself from a string representing a floating point
62 // number. Also used by ToString().
63 static void RemoveTrailingZeroes(wxString& s);
64
65 // Remove all thousands separators from a string representing a number.
66 static void RemoveThousandsSeparators(wxString& s);
67};
68
69#endif // _WX_NUMFORMATTER_H_