DEV Community

Mohit Kumar Yadav
Mohit Kumar Yadav

Posted on

1

Format double according to locale

Problem

I was working on an app targeted for Germany. And in German locale 12.5 is written 12,5, 1.050 in German means one thousand and fifty.

Solution

I created 2 utility functions 1st to parse double to de locale and second to convert back to double.

Here is the code

import 'package:intl/intl.dart';

static String deFormat (String val) {
    final deFormat = NumberFormat.decimalPattern('de',);
    return deFormat.format(double.parse(val));
  }


  static num enFormat (String val) {
    final deFormat = NumberFormat.decimalPattern('de',);
    return deFormat.parse(val);
  }

Enter fullscreen mode Exit fullscreen mode

You'll need intl package.

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay