2 Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 #include "locale_convert.h"
29 locale_convert (int x, int)
32 snprintf (buffer, sizeof(buffer), "%d", x);
38 locale_convert (int64_t x, int)
41 snprintf (buffer, sizeof(buffer), "%" PRId64, x);
47 locale_convert (float x, int precision)
50 snprintf (format, sizeof(format), "%%.%df", precision);
52 snprintf (buffer, sizeof(buffer), format, x);
58 locale_convert (double x, int precision)
61 snprintf (format, sizeof(format), "%%.%df", precision);
63 snprintf (buffer, sizeof(buffer), format, x);
69 locale_convert (string x, int)
76 locale_convert (char* x, int)
83 locale_convert (char const * x, int)
90 locale_convert (string x, int)
93 sscanf (x.c_str(), "%d", &y);
99 locale_convert (string x, int)
102 sscanf (x.c_str(), "%" PRId64, &y);
108 locale_convert (string x, int)
111 sscanf (x.c_str(), "%f", &y);
117 locale_convert (string x, int)
120 sscanf (x.c_str(), "%lf", &y);