I have double value
double myNum = 110700.00;
I want to modify it's format using NumberFormat
110 700
How it can be done?
You can't do it without changing locale because GROUP_SEP is final.
However, if you don't mind changing locale, which you can do on any particular instance, for example with new NumberFormat('###,000', 'fr')
then pick any locale (e.g. French) which uses non-breaking space
as the GROUP_SEP. Of course, you then end up with ,
as your decimal separator but if you don't ever use it then it's moot. That happens to work for the example in the question, but doesn't generalize.
It's possible (though fragile) to define your own language. So if you happen to be an English-speaking Australian who prefers non-breaking space
as your group separator then define your own locale (e.g. zz
)
import 'package:intl/intl.dart';
import 'package:intl/number_symbols_data.dart';
import 'package:intl/number_symbols.dart';
main() {
numberFormatSymbols['zz'] = new NumberSymbols(
NAME: "zz",
DECIMAL_SEP: '.',
GROUP_SEP: '\u00A0',
PERCENT: '%',
ZERO_DIGIT: '0',
PLUS_SIGN: '+',
MINUS_SIGN: '-',
EXP_SYMBOL: 'e',
PERMILL: '\u2030',
INFINITY: '\u221E',
NAN: 'NaN',
DECIMAL_PATTERN: '#,##0.###',
SCIENTIFIC_PATTERN: '#E0',
PERCENT_PATTERN: '#,##0%',
CURRENCY_PATTERN: '\u00A4#,##0.00',
DEF_CURRENCY_CODE: 'AUD',
);
print(new NumberFormat('###,000', 'zz').format(110700));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With