Search code examples
flutterint

int to double I think 1050 to 10.50


been trying to figure this one out for days not, I am using square payments and the amounts are sent as an int 150 is = £1.50p but I am struggling to convert it to £1.50 in flutter.. would appreciate if someone could help.


Solution

  • If I am reading your question correctly, I believe that this will do the trick.

    The package is here: https://pub.dev/packages/intl#-readme-tab-

    Code:

    import 'package:intl/intl.dart';
    import 'package:flutter/material.dart';
    
    void main() => runApp(Converter());
    
    class Converter extends StatelessWidget {
      final currency =
          new NumberFormat.simpleCurrency(name: 'GBP', decimalDigits: 2);
      final int _money = 150;
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: Scaffold(
            appBar: AppBar(
              title: Text('Money converter'),
            ),
            body: new Center(
                child: new Text('${currency.format(_money / 100)}',
                    style: new TextStyle(
                        color: Colors.indigo,
                        fontSize: 30,
                        fontWeight: FontWeight.w800))),
          ),
        );
      }
    }
    

    output: // £1.50