MCPcopy Create free account
hub / github.com/KDE/okular / numberToString

Method numberToString

core/script/js_util.cpp:172–205  ·  view source on GitHub ↗

Converts a Number to a String using the given separator style * * String numberToString( Number number, int formatStyle, int precision, int separatorStyle ) * * formatStyle is an integer denoting format style * 0 => default format style * 1 => fixed format style * * sepStyle is an integer denoting separator style * 0 => . as decimal separator , as thousand sep

Source from the content-addressed store, hash-verified

170 * 4 => . as decimal separator ’ as thousand separators => 1’234.56%
171 */
172QString JSUtil::numberToString(double number, int formatStyle, int precision, int separatorStyle) const
173{
174 if (std::isnan(number)) {
175 return QStringLiteral("NaN");
176 }
177
178 std::wostringstream oss;
179 std::numpunct<wchar_t> *customFormatter;
180 switch (separatorStyle) {
181 case 1:
182 customFormatter = new Style1();
183 break;
184 case 2:
185 customFormatter = new Style2();
186 break;
187 case 3:
188 customFormatter = new Style3();
189 break;
190 case 4:
191 customFormatter = new Style4();
192 break;
193 default:
194 customFormatter = new Style0();
195 break;
196 }
197 oss.imbue(std::locale(oss.getloc(), customFormatter));
198
199 if (formatStyle == 1) {
200 std::fixed(oss);
201 }
202 oss << std::setprecision(precision) << number;
203
204 return QString::fromStdWString(oss.str());
205}
206
207/** Converts a String to a Number trying with the current locale first and
208 * if that fails trying with the reverse locale for the decimal separator

Callers 3

AFSimple_CalculateFunction · 0.80
AFNumber_FormatFunction · 0.80
AFPercent_FormatFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected