convertNumberToText method
Implementation
String convertNumberToText(int number) {
if (number < 0) {
throw Exception('Cannot convert negative numbers');
}
if (number == 0) return mapper.zeroText;
final segments = splitter.splitNumber(number);
var numberText = '';
for (int i = 0; i < segments.length; i++) {
final segment = segments[i];
if (language == "ar") {
final segmentNumberText = getNumberText(segment.number);
if (segmentNumberText != null) {
final shouldAddSpace = numberText.isNotEmpty;
if (shouldAddSpace) numberText += mapper.segmentSpacer;
numberText += segmentNumberText;
continue;
}
}
if (segment.segmentNumber != 0) {
final segmentText = getTextForNumberLessThan1000(segment.segmentNumber);
final shouldAddSpace = numberText.isNotEmpty && segmentText.isNotEmpty;
if (shouldAddSpace) numberText += mapper.segmentSpacer;
numberText += segmentText + segment.magnitude;
}
}
return numberText.trim();
}