Skip to content

Commit

Permalink
Try to convert doubles with comma as decimal point
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Jun 9, 2018
1 parent e56b72a commit 2628075
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/core/qgsfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
7 changes: 6 additions & 1 deletion tests/src/core/testqgsfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 2628075

Please sign in to comment.