| 
    QGIS API Documentation
    3.26.3-Buenos Aires (65e4edfdad)
    
   | 
 
 
 
 
Go to the documentation of this file.
   26   formatter( QChar thousands, 
bool showThousands, QChar decimal )
 
   46   return QStringLiteral( 
"basic" );
 
   51   return QObject::tr( 
"Number" );
 
   61   const QChar decimal = mDecimalSeparator.isNull() ? context.
decimalSeparator() : mDecimalSeparator;
 
   62   std::basic_stringstream<wchar_t> os;
 
   63   os.imbue( std::locale( os.getloc(), 
new formatter( mThousandsSeparator.isNull() ? context.
thousandsSeparator() : mThousandsSeparator,
 
   64                          mShowThousandsSeparator,
 
   69     switch ( mRoundingType )
 
   72         os << std::fixed << std::setprecision( mNumberDecimalPlaces );
 
   84           os << std::fixed << std::setprecision( mNumberDecimalPlaces - 1 ) << 0.0;
 
   89           const int d = std::floor( std::log10( value < 0 ? -value : value ) ) + 1;
 
   90           const double order = std::pow( 10.0, mNumberDecimalPlaces - d );
 
   91           os << std::fixed << std::setprecision( std::max( mNumberDecimalPlaces - d, 0 ) ) << std::round( value * order ) / order;
 
   99     os << std::scientific << std::setprecision( mNumberDecimalPlaces );
 
  106   QString res = QString::fromStdWString( os.str() );
 
  108   if ( mShowPlusSign && value > 0 )
 
  111   if ( !mShowTrailingZeros && res.contains( decimal ) )
 
  113     int trimPoint = res.length() - 1;
 
  117       while ( res.at( trimPoint ).toUpper() != context.
exponential().toUpper() )
 
  123     while ( res.at( trimPoint ) == context.
zeroDigit() )
 
  126     if ( res.at( trimPoint ) == decimal )
 
  129     const QString original = res;
 
  130     res.truncate( trimPoint + 1 );
 
  132       res += original.mid( ePoint );
 
  145   std::unique_ptr< QgsBasicNumericFormat > res = std::make_unique< QgsBasicNumericFormat >();
 
  147   return res.release();
 
  153   res.insert( QStringLiteral( 
"decimals" ), mNumberDecimalPlaces );
 
  154   res.insert( QStringLiteral( 
"show_thousand_separator" ), mShowThousandsSeparator );
 
  155   res.insert( QStringLiteral( 
"show_plus" ), mShowPlusSign );
 
  156   res.insert( QStringLiteral( 
"show_trailing_zeros" ), mShowTrailingZeros );
 
  157   res.insert( QStringLiteral( 
"rounding_type" ), 
static_cast< int >( mRoundingType ) );
 
  158   res.insert( QStringLiteral( 
"thousand_separator" ), mThousandsSeparator );
 
  159   res.insert( QStringLiteral( 
"decimal_separator" ), mDecimalSeparator );
 
  165   mNumberDecimalPlaces = 
configuration.value( QStringLiteral( 
"decimals" ), 6 ).toInt();
 
  166   mShowThousandsSeparator = 
configuration.value( QStringLiteral( 
"show_thousand_separator" ), 
true ).toBool();
 
  167   mShowPlusSign = 
configuration.value( QStringLiteral( 
"show_plus" ), 
false ).toBool();
 
  168   mShowTrailingZeros = 
configuration.value( QStringLiteral( 
"show_trailing_zeros" ), 
false ).toBool();
 
  170   mThousandsSeparator = 
configuration.value( QStringLiteral( 
"thousand_separator" ), QChar() ).toChar();
 
  171   mDecimalSeparator = 
configuration.value( QStringLiteral( 
"decimal_separator" ), QChar() ).toChar();
 
  176   return mNumberDecimalPlaces;
 
  186   return mShowThousandsSeparator;
 
  196   return mShowPlusSign;
 
  206   return mShowTrailingZeros;
 
  216   return mRoundingType;
 
  221   mRoundingType = type;
 
  226   return mThousandsSeparator;
 
  231   mThousandsSeparator = character;
 
  236   return mDecimalSeparator;
 
  241   mDecimalSeparator = character;
 
  
The class is used as a container of context for various read/write operations on other objects.
 
QChar exponential() const
Returns the exponential character.
 
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
 
QChar positiveSign() const
Returns the positive sign character.
 
QChar zeroDigit() const
Returns the zero digit character.
 
QChar decimalSeparator() const
Returns the decimal separator character.
 
A context for numeric formats.
 
QChar thousandsSeparator() const
Returns the thousands separator character.