fromQaFunc function
Implementation
String fromQaFunc(BigInt? qa, Units unit, {pad = false}) {
if (unit.toString() == 'qa') {
return qa.toString();
}
String? baseStr = unitMap[unit];
if (baseStr == null) {
throw 'No unit of type ${unit} exists.';
}
BigInt base = BigInt.parse(baseStr);
int baseNumDecimals = baseStr.length - 1;
String fraction = ((qa!.abs()) % base).toString();
while (fraction.length < baseNumDecimals) {
fraction = '0${fraction}';
}
var reg = new RegExp(r"/^([0-9]*[1-9]|0)(0*)/");
// print(reg.allMatches(fraction));
if (pad == false) {
fraction = fraction.splitMapJoin(reg);
}
String whole = (qa ~/ base).toString();
return fraction == '0' ? '${whole}' : '${whole}.${fraction}';
}