format method

String format(
  1. String format
)

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

The following patterns can be used for format.

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

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 d = 12.343;
print(d.format("###.0#")); // 12.34

Please note that decimal points will be rounded.

小数点を丸めるときは四捨五入されますのでご注意ください。

Implementation

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