本文整理汇总了C++中QLocale::decimalPoint方法的典型用法代码示例。如果您正苦于以下问题:C++ QLocale::decimalPoint方法的具体用法?C++ QLocale::decimalPoint怎么用?C++ QLocale::decimalPoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QLocale
的用法示例。
在下文中一共展示了QLocale::decimalPoint方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getBlankSkip
/**
*@brief Retourne la tolérance au blanc.
*@return QString - Valeur du champ.
*/
QString DockConf::getBlankSkip()
{
QString res;
QLocale localedecimalPoint;
double value = double(blankSkipSpinBox->value())/100;
res = QString::number(value,'f',2);
#if defined(Q_OS_LINUX)
return res.replace(",",localedecimalPoint.decimalPoint());
#else
return res.replace(".",localedecimalPoint.decimalPoint());
#endif
}
示例2: rx
void K3b::FillStatusDisplay::slotCustomSize()
{
// allow the units to be translated
QString gbS = i18n("GB");
QString mbS = i18n("MB");
QString minS = i18n("min");
QLocale const locale = QLocale::system();
// we certainly do not have BD- or HD-DVD-only projects
QString defaultCustom;
if( d->doc->supportedMediaTypes() & K3b::Device::MEDIA_CD_ALL ) {
defaultCustom = d->showTime ? QString("74") + minS : QString("650") + mbS;
}
else {
defaultCustom = locale.toString(4.4,'g',1) + gbS;
}
QRegExp rx( QString("(\\d+\\") + locale.decimalPoint() + "?\\d*)(" + gbS + '|' + mbS + '|' + minS + ")?" );
QRegExpValidator validator( rx, this );
bool ok;
QString size = QInputDialog::getText( this,
i18n("Custom Size"),
i18n("<p>Please specify the size of the medium. Use suffixes <b>GB</b>,<b>MB</b>, "
"and <b>min</b> for <em>gigabytes</em>, <em>megabytes</em>, and <em>minutes</em>"
" respectively."),
QLineEdit::Normal,
defaultCustom,
&ok );
int validatorPos;
if( ok && validator.validate( size, validatorPos ) ) {
// determine size
if( rx.exactMatch( size ) ) {
QString valStr = rx.cap(1);
if( valStr.endsWith( locale.decimalPoint() ) )
valStr += '0';
double val = locale.toDouble( valStr, &ok );
if( ok ) {
QString s = rx.cap(2);
if( s == gbS )
val *= 1024*512;
else if( s == mbS || (s.isEmpty() && !d->showTime) )
val *= 512;
else
val *= 60*75;
d->setCdSize( static_cast<int>( val ) );
}
}
}
}
示例3: initLocale
void Core::initLocale()
{
QLocale systemLocale = QLocale();
#ifndef Q_OS_MAC
setlocale(LC_NUMERIC, NULL);
#else
setlocale(LC_NUMERIC_MASK, NULL);
#endif
char *separator = localeconv()->decimal_point;
if (QString::fromUtf8(separator) != QChar(systemLocale.decimalPoint())) {
//qDebug()<<"------\n!!! system locale is not similar to Qt's locale... be prepared for bugs!!!\n------";
// HACK: There is a locale conflict, so set locale to C
// Make sure to override exported values or it won't work
qputenv("LANG", "C");
#ifndef Q_OS_MAC
setlocale(LC_NUMERIC, "C");
#else
setlocale(LC_NUMERIC_MASK, "C");
#endif
systemLocale = QLocale::c();
}
systemLocale.setNumberOptions(QLocale::OmitGroupSeparator);
QLocale::setDefault(systemLocale);
}
示例4: formatLocFPNumber
QString formatLocFPNumber(double d)
{
QString result = toqstr(formatFPNumber(d));
QLocale loc;
result.replace('.', loc.decimalPoint());
return result;
}
示例5: format
QString BitcoinUnits::format(int unit, qint64 n, bool fPlus)
{
// Note: not using straight sprintf here because we do NOT want
// localized number formatting.
if(!valid(unit))
return QString(); // Refuse to format invalid unit
qint64 coin = factor(unit);
int num_decimals = decimals(unit);
qint64 n_abs = (n > 0 ? n : -n);
qint64 quotient = n_abs / coin;
qint64 remainder = n_abs % coin;
QString remainder_str = QString::number(remainder).rightJustified(num_decimals, '0');
// Right-trim excess zeros after the decimal point
int nTrim = 0;
for (int i = remainder_str.size()-1; i>=2 && (remainder_str.at(i) == '0'); --i)
++nTrim;
remainder_str.chop(nTrim);
QString quotientString;
if (n < 0) {
quotient = -quotient;
}
else if ( n > 0 && fPlus ) {
quotientString += "+";
}
QLocale local;
return quotientString + local.toString(quotient) + local.decimalPoint() + remainder_str;
}
示例6: sampleToDateTimeString
QString DataFile::sampleToDateTimeString(int sample, InfoTable::TimeMode mode)
{
QLocale locale;
if (mode == InfoTable::TimeMode::size)
{
mode = infoTable.getTimeMode();
}
if (mode == InfoTable::TimeMode::samples)
{
return QString::number(sample);
}
else if (mode == InfoTable::TimeMode::offset)
{
QDateTime date = sampleToOffset(sample);
return QString::number(date.date().day() - 1) + "d " + date.toString("hh:mm:ss" + QString(locale.decimalPoint()) + "zzz");
}
else if (mode == InfoTable::TimeMode::real)
{
return sampleToDate(sample).toString("d.M.yyyy hh:mm:ss" + QString(locale.decimalPoint()) + "zzz");
}
return QString();
}
示例7: qDebug
MapValidator::QValidator::State MapValidator::validate(QString &s, int &i) const
{
qDebug()<<"validating table input";
if (s.isEmpty() || s == "-") {
return QValidator::Intermediate;
}
QLocale locale;
QChar decimalPoint = locale.decimalPoint();
int charsAfterPoint = s.length() - s.indexOf(decimalPoint) -1;
if (charsAfterPoint > decimals() && s.indexOf(decimalPoint) != -1) {
return QValidator::Invalid;
}
bool ok;
double d = locale.toDouble(s, &ok);
if (ok && d >= bottom() && d <= top()) {
return QValidator::Acceptable;
} else {
return QValidator::Invalid;
}
}
示例8: parseDouble
double LonLatParser::parseDouble(const QString& input)
{
// Decide by decimalpoint if system locale or C locale should be tried.
// Otherwise if first trying with a system locale when the string is in C locale,
// the "." might be misinterpreted as thousands group separator and thus a wrong
// value yielded
QLocale locale = QLocale::system();
return input.contains(locale.decimalPoint()) ? locale.toDouble(input) : input.toDouble();
}
示例9: changed
void GuiParagraph::changed()
{
QLocale loc;
// We apply immediately, except if we have custom line spacing
// with an intermediate result (trailing decimal separator) or
// an invalid value (which might as well be intermediate)
if (synchronizedViewCB->isChecked()
&& (linespacing->currentIndex() != 4
|| (!linespacingValue->text().endsWith(loc.decimalPoint())
&& linespacingValue->hasAcceptableInput())))
on_applyPB_clicked();
}
示例10: stringForVal
QString QcNumberBox::stringForVal( double val )
{
QLocale loc = locale();
QString str = loc.toString( val, 'f', _maxDec );
int i = str.indexOf( loc.decimalPoint() );
if( i > -1 ) {
QString dec = str.mid(i+1);
while( dec.size() > _minDec && dec.endsWith('0') ) dec.chop(1);
if( dec.isEmpty() )
str = str.left(i);
else
str = str.left(i+1) + dec;
}
return str;
}
示例11: compactFormatDouble
QString Utility::compactFormatDouble(double value, int prec, const QString& unit)
{
QLocale locale = QLocale::system();
QChar decPoint = locale.decimalPoint();
QString str = locale.toString(value, 'f', prec);
while (str.endsWith('0') || str.endsWith(decPoint)) {
if (str.endsWith(decPoint)) {
str.chop(1);
break;
}
str.chop(1);
}
if( !unit.isEmpty() )
str += (QLatin1Char(' ')+unit);
return str;
}
示例12: validate
QValidator::State LengthValidator::validate(QString & qtext, int &) const
{
QLocale loc;
bool ok;
double d = loc.toDouble(qtext.trimmed(), &ok);
// QLocale::toDouble accepts something like "1."
// We don't.
bool dp = qtext.endsWith(loc.decimalPoint());
if (!ok) {
// Fall back to C
QLocale c(QLocale::C);
d = c.toDouble(qtext.trimmed(), &ok);
dp = qtext.endsWith(c.decimalPoint());
}
if (ok && unsigned_ && d < 0)
return QValidator::Invalid;
if (qtext.isEmpty() || (ok && !dp))
return QValidator::Acceptable;
string const text = fromqstr(qtext);
if (glue_length_) {
GlueLength gl;
if (unsigned_ && gl.len().value() < 0)
return QValidator::Invalid;
return (isValidGlueLength(text, &gl)) ?
QValidator::Acceptable : QValidator::Intermediate;
}
Length l;
bool const valid_length = isValidLength(text, &l);
if (!valid_length)
return QValidator::Intermediate;
if (no_bottom_)
return QValidator::Acceptable;
if (unsigned_ && l.value() < 0)
return QValidator::Invalid;
return b_.inPixels(100) <= l.inPixels(100) ?
QValidator::Acceptable : QValidator::Intermediate;
}
示例13: fromString
QVariant KexiTextFormatter::fromString(const QString& text) const
{
if (!d->field)
return QVariant();
switch (d->field->type()) {
case KDbField::Text:
case KDbField::LongText:
return text;
case KDbField::Byte:
case KDbField::ShortInteger:
return text.toShort();
//! @todo uint, etc?
case KDbField::Integer:
return text.toInt();
case KDbField::BigInteger:
return text.toLongLong();
case KDbField::Boolean:
//! @todo temporary solution for booleans!
return text == "1";
case KDbField::Date:
return d->dateFormatter->stringToVariant(text);
case KDbField::Time:
return d->timeFormatter->stringToVariant(text);
case KDbField::DateTime:
return KexiDateTimeFormatter::fromString(
*d->dateFormatter, *d->timeFormatter, text);
case KDbField::Float:
case KDbField::Double: {
// replace custom decimal symbol with '.' as required by to{Float|Double}()
QString fixedText(text);
QLocale locale;
fixedText.replace(locale.decimalPoint(), '.');
if (d->field->type() == KDbField::Double)
return fixedText.toDouble();
return fixedText.toFloat();
}
default:
break;
}
return text;
//! @todo more data types!
}
示例14: format
QString UnitFormatter::format(const double value, QString unit)
{
QLocale locale;
QString result;
ushort prefix;
QTextStream out(&result);
out.setLocale(locale);
if(value>0.999999999){
double aux = value;
int multiplier = 0;
while(aux>=1000){
++multiplier;
aux=aux/1000;
}
prefix = BIG_PREFIXES[multiplier];
out.setRealNumberPrecision(2);
out.setNumberFlags(out.numberFlags() & ~QTextStream::ForcePoint);
out.setRealNumberNotation(QTextStream::FixedNotation);
out<<aux;
}
else {
double aux = value;
int divider = 0;
if(aux>SMALLEST_VALUE){
while(aux<0.999999999){
++divider;
aux=aux*1000;
}
}
prefix = SMALL_PREFIXES[divider];
out.setRealNumberPrecision(2);
out.setRealNumberNotation(QTextStream::FixedNotation);
out<<aux;
}
removeTrailingZeros(result, locale.decimalPoint());
if(prefix){
out<<QChar(prefix);
}
if(unit!=0){
out<<unit;
}
return result;
}
示例15: formatDoubleForDisplay
QString formatDoubleForDisplay(double num, double decimalPlacesToDisplay)
{
QLocale locale;
QString withCommas = locale.toString(num, 'f');
QString final;
bool pastDecimalPoint = false;
int numbersPastDecimalPoint = 0;
for (int i = 0; i < withCommas.length(); ++i)
{
final += withCommas[i];
if (pastDecimalPoint)
++numbersPastDecimalPoint;
if (numbersPastDecimalPoint >= decimalPlacesToDisplay)
return final;
if (withCommas[i] == locale.decimalPoint())
pastDecimalPoint = true;
}