Skip to content
Permalink
Browse files

Try to convert doubles with comma as decimal point

  • Loading branch information
elpaso committed Jun 5, 2018
1 parent e56b72a commit 26280751a6395e1eee71e51ba36f7168b419e191
Showing with 13 additions and 1 deletion.
  1. +7 −0 src/core/qgsfield.cpp
  2. +6 −1 tests/src/core/testqgsfield.cpp
@@ -281,6 +281,13 @@ bool QgsField::convertCompatible( QVariant &v ) const
return true;
}

// Give it a chance to convert to double since we accept both comma and dot as decimal point
QVariant tmp( v );
if ( d->type == QVariant::Double && !tmp.convert( d->type ) )
{
v = v.toString().replace( ',', '.' );
}

if ( !v.convert( d->type ) )
{
v = QVariant( d->type );
@@ -346,7 +346,6 @@ void TestQgsField::displayString()
QCOMPARE( doubleFieldNoPrec.displayString( 5.005005005 ), QString( "5,005005005" ) );
QCOMPARE( doubleFieldNoPrec.displayString( 599999898999.0 ), QString( "599.999.898.999" ) );


}

void TestQgsField::convertCompatible()
@@ -475,6 +474,12 @@ void TestQgsField::convertCompatible()
QVERIFY( !stringWithLen.convertCompatible( stringVar ) );
QCOMPARE( stringVar.type(), QVariant::String );
QCOMPARE( stringVar.toString(), QString( "lon" ) );

//double with ',' as decimal separator
QVariant doubleCommaVar( "1,2345" );
QVERIFY( doubleField.convertCompatible( doubleCommaVar ) );
QCOMPARE( doubleCommaVar.type(), QVariant::Double );
QCOMPARE( doubleCommaVar.toString(), QString( "1.2345" ) );
}

void TestQgsField::dataStream()

0 comments on commit 2628075

Please sign in to comment.
You can’t perform that action at this time.