Skip to content

Commit

Permalink
Show numbers with space as thousand separator
Browse files Browse the repository at this point in the history
  • Loading branch information
magnesj committed Jan 19, 2024
1 parent 34ebd4d commit 5f819cd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ApplicationLibCode/Application/RiaMemoryCleanup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
/////////////////////////////////////////////////////////////////////////////////

#include "RiaMemoryCleanup.h"
#include "RiaStdStringTools.h"

#include "RigCaseCellResultsData.h"
#include "RigEclipseResultInfo.h"
Expand Down Expand Up @@ -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 ) );
}
}
Expand Down
20 changes: 20 additions & 0 deletions ApplicationLibCode/Application/Tools/RiaStdStringTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions ApplicationLibCode/Application/Tools/RiaStdStringTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class RiaStdStringTools
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 );
Expand Down

0 comments on commit 5f819cd

Please sign in to comment.