Waqar Younus
Waqar Younus

Reputation: 107

How to format integer value with comma separator in flutter

I want to convert integer price value to comma separated value example is sharing with you.

For Example

val = 132450

out of

val = 1,32450

Upvotes: 1

Views: 7529

Answers (1)

Guilherme Dias
Guilherme Dias

Reputation: 148

try this:

import 'package:intl/intl.dart';

final value = new NumberFormat("#,##0.00", "en_US");

void main () {

  print("Ex. 1: ${value.format(123456789.75)}");
  print("Ex. 2: ${value.format(.7)}");
  print("Ex. 3: ${value.format(12345678975/100)}");
  print("Ex. 4: ${value.format(int.parse('12345678975')/100)}");
  print("Ex. 5: ${value.format(double.parse('123456789.75'))}");

/* Output :  

Ex. 1: 123,456,789.75
Ex. 2: 0.70
Ex. 3: 123,456,789.75
Ex. 4: 123,456,789.75
Ex. 5: 123,456,789.75


 pubspec.yaml :

  dev_dependencies:
    intl: any

   Run pub install to install "intl"  
*/
}

Upvotes: 11

Related Questions