mirror of
https://github.com/OPM/ResInsight.git
synced 2026-11-03 12:50:52 -06:00
- Use 'g' format with precision for AUTO in valueToText - Remove sprintfFormat function and its declaration - Replace individual tests with a single parameterized test - Expand test coverage for all formats and precisions
33 lines
1.0 KiB
C++
33 lines
1.0 KiB
C++
#include "cafPdmUiNumberFormat.h"
|
|
|
|
#include "cafAppEnum.h"
|
|
|
|
template <>
|
|
void caf::AppEnum<caf::NumberFormatType>::setUp()
|
|
{
|
|
addItem( caf::NumberFormatType::AUTO, "AUTO", "Automatic" );
|
|
addItem( caf::NumberFormatType::FIXED, "FIXED", "Fixed, decimal" );
|
|
addItem( caf::NumberFormatType::SCIENTIFIC, "SCIENTIFIC", "Scientific notation" );
|
|
setDefault( caf::NumberFormatType::FIXED );
|
|
};
|
|
|
|
namespace caf
|
|
{
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
QString PdmUiNumberFormat::valueToText( double value, NumberFormatType numberFormat, int precision )
|
|
{
|
|
switch ( numberFormat )
|
|
{
|
|
case NumberFormatType::FIXED:
|
|
return QString::number( value, 'f', precision );
|
|
case NumberFormatType::SCIENTIFIC:
|
|
return QString::number( value, 'e', precision );
|
|
default:
|
|
return QString::number( value, 'g', precision );
|
|
}
|
|
}
|
|
|
|
} // namespace caf
|