MData
MData

Reputation: 15

How to convert a number from 20,95 to 20.95 in Dart/Flutter?

I get a String (20.95) from a spreadsheet and need to convert it to Double (20.95).

I tried using the Intl package, using

double.parse(NumberFormat.currency(locale: 'en_US').format(price)

but it always returns the value with a comma.

Error: FormatException: Invalid double 20,95

Upvotes: 0

Views: 85

Answers (1)

stonith404
stonith404

Reputation: 530

The following code replaces the comma with a point and then parses it to a double.

double.parse(yourString.replaceAll(",", ".")),

Upvotes: 1

Related Questions