The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


Number::Format::Metric - Format number with metric prefix


This document describes version 0.602 of Number::Format::Metric (from Perl distribution Number-Format-Metric), released on 2023-02-14.


 use Number::Format::Metric qw(format_metric);

 format_metric(14     , {base=>10});               # => "14.0"
 format_metric(14     , {base=>10, precision=>0}); # => "14"
 format_metric(12001  , {base=> 2, precision=>1}); # => "11.7k"
 format_metric(12001  , {base=>10, precision=>3}); # => "12.001ki"
 format_metric(-0.0017, {base=>10});               # => "-1.7m"
 format_metric(1.26e6 , {base=>10});               # => "1.3Mi"


None exported by default but all of them exportable.

format_metric($num, \%opts) => STR

Format $num using metric prefix. Locale settings are respected (this module uses locale). Might produce non-Latin Unicode characters (e.g. μ for 1e-6 prefix). Known options:

  • base => INT (either 2 or 10, default: 2)

  • precision => INT

  • i_mark => BOOL (default: 1)

    Give "i" suffix to prefixes when in base 10 for k, M, G, T, and so on.


Please visit the project's homepage at


Source repository is at


Other number formatting modules: Number::Format, Format::Human::Bytes, Number::Bytes::Human.


perlancar <>


Steven Haryanto <>


To contribute, you can send patches by email/via RT, or send pull requests on GitHub.

Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via:

 % prove -l

If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, Pod::Weaver::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond that are considered a bug and can be reported to me.


This software is copyright (c) 2023, 2014, 2013 by perlancar <>.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


Please report any bugs or feature requests on the bugtracker website

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.