Show numbers with space as thousand separator

This commit is contained in:
Magne Sjaastad
2024-01-19 06:14:00 +01:00
parent df083a870a
commit 33f18a7c8f
3 changed files with 26 additions and 1 deletions

View File

@@ -17,6 +17,7 @@
/////////////////////////////////////////////////////////////////////////////////
#include "RiaMemoryCleanup.h"
#include "RiaStdStringTools.h"
#include "RigCaseCellResultsData.h"
#include "RigEclipseResultInfo.h"
@@ -399,9 +400,11 @@ std::pair<QString, QString> RiaMemoryCleanup::createMemoryReport()
size_t memory = valueCount * sizeof( double );
totalMemoryForCase += memory;
auto formattedValueCount = RiaStdStringTools::formatThousandGrouping( valueCount );
caseReport += QString( " %1 MB\tValue count %2, %3\n" )
.arg( memory / 1024.0 / 1024.0, 0, 'f', 2 )
.arg( valueCount )
.arg( QString::fromStdString( formattedValueCount ) )
.arg( QString::fromStdString( name ) );
}
}

View File

@@ -138,6 +138,26 @@ bool RiaStdStringTools::startsWithAlphabetic( const std::string& s )
return isalpha( s[0] ) != 0;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::string RiaStdStringTools::formatThousandGrouping( long value )
{
class my_punct : public std::numpunct<char>
{
protected:
virtual char do_decimal_point() const { return '.'; }
virtual char do_thousands_sep() const { return ' '; }
virtual std::string do_grouping() const { return std::string( "\3" ); }
};
std::ostringstream os;
os.imbue( std::locale( os.getloc(), new my_punct ) );
fixed( os );
os << value;
return os.str();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -43,6 +43,8 @@ public:
static bool containsAlphabetic( const std::string& s );
static bool startsWithAlphabetic( const std::string& s );
static std::string formatThousandGrouping( long value );
// Conversion using fastest known approach
static bool toDouble( const std::string_view& s, double& value );
static bool toInt( const std::string_view& s, int& value );