format method

String format(
  1. String format
)

Enter format to replace the value of int with a string.

The following patterns can be used for format.

formatを入力してintの値を文字列に置き換えます。

formatには下記のパターンを使用することが可能です。

  • 0 A single digit
  • # A single digit, omitted if the value is zero
  • . Decimal separator
  • - Minus sign
  • , Grouping separator
  • E Separates mantissa and expontent
  • + - Before an exponent, to say it should be prefixed with a plus sign.
  • % - In prefix or suffix, multiply by 100 and show as percentage
  • ‰ (\u2030) In prefix or suffix, multiply by 1000 and show as per mille
  • ¤ (\u00A4) Currency sign, replaced by currency name
  • ' Used to quote special characters
  • ; Used to separate the positive and negative patterns (if both present)

For example,

final i = 12;
print(i.format("000")); // 012

Implementation

String format(String format) {
  assert(format.isNotEmpty, "The format is empty.");
  return NumberFormat(format).format(this);
}