Caio Borghi
Caio Borghi

Reputation: 76

Parsing number in flutter/dart

I'm trying to parse the string "78,74"(which is a valid number in Brazil's format) to double, but I'm getting Format Exception and I can't find any way to parse it... Already searched in intl docs but there's nothing helpful.

I don't want to replace the "," with "." because i think that it must be a way to parse it using CultureInfo

My code is like

String x = "78,74";

double d = double.tryParse(x)

Upvotes: 1

Views: 1684

Answers (2)

Ben Konyi
Ben Konyi

Reputation: 3229

Localization support for parsing numbers can be found in package:intl. For this particular case, you're looking for the parse method from NumberFormat.

Upvotes: 1

GPaiva
GPaiva

Reputation: 576

You can use double d = NumberFormat('pt_Br').parse(x) from intl library. You will need to add the dependencies.

Upvotes: 5

Related Questions