Skip to content

Commit 2628075

Browse files
committed
Try to convert doubles with comma as decimal point
1 parent e56b72a commit 2628075

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/core/qgsfield.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,13 @@ bool QgsField::convertCompatible( QVariant &v ) const
281281
return true;
282282
}
283283

284+
// Give it a chance to convert to double since we accept both comma and dot as decimal point
285+
QVariant tmp( v );
286+
if ( d->type == QVariant::Double && !tmp.convert( d->type ) )
287+
{
288+
v = v.toString().replace( ',', '.' );
289+
}
290+
284291
if ( !v.convert( d->type ) )
285292
{
286293
v = QVariant( d->type );

tests/src/core/testqgsfield.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,6 @@ void TestQgsField::displayString()
346346
QCOMPARE( doubleFieldNoPrec.displayString( 5.005005005 ), QString( "5,005005005" ) );
347347
QCOMPARE( doubleFieldNoPrec.displayString( 599999898999.0 ), QString( "599.999.898.999" ) );
348348

349-
350349
}
351350

352351
void TestQgsField::convertCompatible()
@@ -475,6 +474,12 @@ void TestQgsField::convertCompatible()
475474
QVERIFY( !stringWithLen.convertCompatible( stringVar ) );
476475
QCOMPARE( stringVar.type(), QVariant::String );
477476
QCOMPARE( stringVar.toString(), QString( "lon" ) );
477+
478+
//double with ',' as decimal separator
479+
QVariant doubleCommaVar( "1,2345" );
480+
QVERIFY( doubleField.convertCompatible( doubleCommaVar ) );
481+
QCOMPARE( doubleCommaVar.type(), QVariant::Double );
482+
QCOMPARE( doubleCommaVar.toString(), QString( "1.2345" ) );
478483
}
479484

480485
void TestQgsField::dataStream()

0 commit comments

Comments
 (0)