number_display 2.1.4

  • Readme
  • Changelog
  • Example
  • Installing
  • 90


number_display #

Display number smartly within a certain length.

final display = createDisplay(length: 8);

display(-254623933.876)    // result: -254.62M

The conversion follow this rules:

  • result char length will never overflow length
  • replace null, nan or infinity to placeholder
  • use locale string with commas ( 1,234,222 ) as possible ( configurable )
  • trim number with units ( 1.23k ) when length is limited
  • convert scientific notation ( 1.23e+4 ) to friendly form
  • when omitting decimals, you can change the rounding type, default to 'round'
  • no decimal tailing zeros
  • no float error

It also has a JavaScript version

Install #

Add this to your package's pubspec.yaml file:

  number_display: # latest version

Details see

Usage #

In version 2.* we only export a createDisplay function for users to custom their display function. So the real display function has only one input: value . This separates the configuration and usage, which is more simple and clear.

import 'package:number_display/number_display.dart';

final display = createDisplay(
  length: 8,
  decimal: 0,


The complete configuration params are listed in the next section .

If the length overflow, the trimming rules in order are:

  • omit the locale commas
  • slice the decimal by the room left
  • trim the integer with number units ( k, M, G, T, P )
  • if the length is >= 5, any number can be trimmed within it. If it's less than 5 and input number is too long, display will throw an exception.

Conversion examples:


null => ''
double.nan => ''

-123456789.123456789 => '-123.457M'
'123456' => '123,456'
-1.2345e+5 => '-123,450'

With some configs:

  separator: false,
  placeholder: '--'

null => '--'
123456 => '123456'

Configurations #


( default: 9 )

The max length the result would be. length should no less then 5 so that any number can display ( say -123000 ) after trim.


( default: equals to 'length' )

The max decimal length. Note that this is only a constraint. The final precision will be calculated by length, and less than this param. This param is the same as 'length' by default, witch means no additional limit. There will be no decimal trailing zeros.


( default: '' )

The result when the input is neither string nor number, or the input is NaN, Infinity or -Infinity. It will be sliced if longer than length param.


( default: true )

Whether the locale string has commas ( 1,234,222 ), if there are rooms.


( default: RoundingType.round )

The rounding type when omitting decimals, enum in RoundingType.round, RoundingType.floor or RoundingType.ceil.

Blogs #



1.0.0 #


  • Init this package.

1.0.1 #


  • Add some documents.

2.0.0 #


  • Simplify APIs, details in
  • Optimize performance.
  • Add unit test.
  • Remove decimal trailing zeros.

2.0.1 #


  • Enlarge SDK requirement to ">=2.1.0 <3.0.0".

2.1.0 #


  • Add feature: roundingType. Now you can set the way to round the decimal in 'round', 'floor' or 'ceil', witch default to 'round'.
  • When the length is too small, number-display will return the origin value as a string, instead of throwing an error.
  • Change param decimal name to 'precision', and default to equal to param length, witch means no additional limit.
  • Change param comma name to 'separator'.

2.1.2 #


  • Change back param precision name to 'decimal', to avoid confusion with the common 'toPrecision' meaning.
  • Add inner precision limit to avoid float error.

2.1.3 #


  • Update license to 2020.
  • Omit type annotations for local variables in line 73, 79.

2.1.4 #


  • Update readme.


import 'package:number_display/number_display.dart';

final display = createDisplay(length: 8);

main(List<String> args) {
  print(display(-254623933.876));    // result: -254.62M

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  number_display: ^2.1.4

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:number_display/number_display.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 24, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4

Health suggestions

Format lib/number_display.dart.

Run dartfmt to format lib/number_display.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
Dev dependencies
test ^1.6.5