1

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)
2
  • By default it is the way double.tryParse(x) behaving. I dont know something like that you are mentioning exist with yet Flutter(not sure). Why cant you replace comma if exist and replace it with dot and parse using replaceAll Commented Feb 3, 2020 at 23:56
  • Yeah, after more research I think that its the only way... Using replaceAll did the job Commented Feb 4, 2020 at 1:09

2 Answers 2

5

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

Sign up to request clarification or add additional context in comments.

1 Comment

The locale is the 2nd parameter : NumberFormat('', 'pt_Br').parse(x) works
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.