Source www.jianshu.com/p/016a6d1a1…

The main idea behind Flutter is to convert the amount *100 and then round it to int from the last digit to add units if each digit is converted to a Character.

The lastZero identifier determines whether the last one is zero, and if it is, it will be skipped. The tag identifier determines whether there are non-zero digits since the last conversion of the key unit. The TAG2 identifier indicates whether a non-zero digit (newly updated code) has been zeroed in in two places since the last key unit: 1, before the key unit is added, and 2, before the non-zero digit is added.

Note that the length of the

Here’s the code

ConvertNumToChinese (double num) {final List < String > CN_UPPER_NUMBER = [" zero ", "one", "two", "3", "the boss", "wu", "land", "pure", "", "Nine"]; Final List < String > CN_UPPER_MONETRAY_UNIT = [" points ", "Angle", "round", "pick up", "hk", "$"," wan ", "pick up", "hk", "$"," $", "pick up", "hk", "$", "Zhao "," Shi ", "Bai "," Qian "]; Final String CN_FULL = "full "; Final String CN_NEGATIVE = "negative "; Final String CN_ZEOR_FULL = "zero circle" + CN_FULL; double sign = num.sign; if (sign == num) { return CN_ZEOR_FULL; } if (num.toStringasFixed (0).length > 15) {return 'out of limit '; } num = num * 100; int tempValue = int.parse(num.toStringAsFixed(0)).abs(); int p = 10; int i = -1; String CN_UP = ''; bool lastZero = false; bool finish = false; bool tag = false; bool tag2 = false; while (! finish) { if (tempValue == 0) { break; } int positionNum = tempValue % p; double n = (tempValue - positionNum) / 10; tempValue = int.parse(n.toStringAsFixed(0)); String tempChinese = ''; i++; If (positionNum = = 0) {if (CN_UPPER_MONETRAY_UNIT [I] = = "than" | | CN_UPPER_MONETRAY_UNIT [I] = = "$" | | CN_UPPER_MONETRAY_UNIT [I] = = "mega" | | CN_UPPER_MONETRAY_UNIT [I] = = "circle") {if (lastZero && tag2) {CN_UP = CN_UPPER_NUMBER[0] + CN_UP; } CN_UP = CN_UPPER_MONETRAY_UNIT[i] + CN_UP; lastZero = false; tag = true; continue; } if (! lastZero) { lastZero = true; } else { continue; } } else { if (lastZero && ! tag && tag2) { CN_UP = CN_UPPER_NUMBER[0] + CN_UP; } tag = false; tag2 = true; lastZero = false; tempChinese = CN_UPPER_NUMBER[positionNum] + CN_UPPER_MONETRAY_UNIT[i]; } CN_UP = tempChinese + CN_UP; } if (sign < 0) { CN_UP = CN_NEGATIVE + CN_UP; } return CN_UP; }Copy the code

Attached: amount validation regular expression

RegExp e = RegExp(r'^\d+(\.\d+)? $');Copy the code

PS: Initial test available, looking forward to subsequent BUG feedback