@@ -501,10 +501,25 @@ String toCurrencyString(
501501}) {
502502 value = value.replaceAll (_spaceRegex, '' );
503503 if (value.isEmpty) {
504- return value;
504+ value = '0' ;
505505 }
506- String mSeparator = _getMantissaSeparator (thousandSeparator, mantissaLength);
507- String tSeparator = _getThousandSeparator (thousandSeparator);
506+ String mSeparator = _getMantissaSeparator (
507+ thousandSeparator,
508+ mantissaLength,
509+ );
510+ String tSeparator = _getThousandSeparator (
511+ thousandSeparator,
512+ );
513+
514+ /// нужно только для того, чтобы недопустить числа начинающиеся с нуля
515+ /// 04.00 и т.д
516+ value = toNumericString (
517+ value,
518+ allowAllZeroes: false ,
519+ allowHyphen: true ,
520+ allowPeriod: true ,
521+ mantissaSeparator: mSeparator,
522+ );
508523 String ? fractionalSeparator =
509524 mantissaLength > 0 ? _detectFractionSeparator (value) : null ;
510525
@@ -532,7 +547,8 @@ String toCurrencyString(
532547 }
533548
534549 final str = sb.toString ();
535- final evenPart = addedMantissaSeparator ? str.substring (0 , str.indexOf ('.' )) : str;
550+ final evenPart =
551+ addedMantissaSeparator ? str.substring (0 , str.indexOf ('.' )) : str;
536552
537553 int skipEvenNumbers = 0 ;
538554 String shorteningName = '' ;
@@ -641,46 +657,13 @@ String toCurrencyString(
641657 return value;
642658}
643659
644- /// просто меняет точки и запятые местами
645- // String _swapCommasAndPeriods(String input) {
646- // var temp = input;
647- // if (temp.indexOf('.,') > -1) {
648- // temp = temp.replaceAll('.,', ',,');
649- // }
650- // temp = temp.replaceAll('.', 'PERIOD').replaceAll(',', 'COMMA');
651- // temp = temp.replaceAll('PERIOD', ',').replaceAll('COMMA', '.');
652- // return temp;
653- // }
654-
655660bool isUnmaskableSymbol (String ? symbol) {
656661 if (symbol == null || symbol.length > 1 ) {
657662 return false ;
658663 }
659664 return _isMaskSymbolRegExp.hasMatch (symbol);
660665}
661666
662- // String _getRoundedValue(
663- // String numericString,
664- // double roundTo,
665- // ) {
666- // assert(roundTo != 0.0);
667- // var numericValue = double.tryParse(numericString) ?? 0.0;
668- // var result = numericValue / roundTo;
669-
670- // /// e.g. for a number of 1700 return 1.7, instead of 1
671- // /// after rounding to 1000
672- // var remainder = result.remainder(1.0);
673- // String prepared;
674- // if (remainder != 0.0) {
675- // prepared = result.toStringAsFixed(2);
676- // if (prepared[prepared.length - 1] == '0') {
677- // prepared = prepared.substring(0, prepared.length - 1);
678- // }
679- // return prepared;
680- // }
681- // return result.toInt().toString();
682- // }
683-
684667/// Checks if currency is fiat
685668bool isFiatCurrency (String currencyId) {
686669 if (currencyId.length != 3 ) {
@@ -702,14 +685,6 @@ bool isCryptoCurrency(String currencyId) {
702685 return ! isFiatCurrency (currencyId);
703686}
704687
705- /// simply adds a period to an existing fractional part
706- /// or adds an empty fractional part if it was not filled
707- // String _postProcessMantissa(String mantissaValue, int mantissaLength) {
708- // if (mantissaLength < 1) return '';
709- // if (mantissaValue.isNotEmpty) return '.$mantissaValue';
710- // return '.${List.filled(mantissaLength, '0').join('')}';
711- // }
712-
713688/// [character] a character to check if it's a digit against
714689/// [positiveOnly] if true it will not allow a minus (dash) character
715690/// to be accepted as a part of a digit
0 commit comments