format method

String format()

Implementation

String format() {
  final intStr = mag.format();
  if (identical(sig, 0)) {
    return intStr;
  }
  final sb = StringBuilder(intStr);
  final head = sb.str[0];
  final specialHead = identical(head, mag.getSystem().getPositiveChar()) ||
      identical(head, mag.getSystem().getNegativeChar());
  if (specialHead) {
    sb.remove(0, 1);
  }
  while (sb.length < sig + 1) {
    sb.insert(0, mag.getSystem().toChar(0));
  }
  sb.insert(sb.length - sig, mag.getSystem().getRadixPointChar());
  if (identical(sb.length - sig, 0)) {
    sb.insert(0, mag.getSystem().toChar(0));
  }
  if (specialHead) {
    sb.insert(0, head);
  }
  return sb.toString();
}