number_display
너비 제한이 있는 컴포넌트에 데이터를 표시하려면 이 함수가 숫자를 특정 차트 길이로 스마트하게 변환하는 데 도움을 줍니다. 간단하고, 단순하며, 유연하고 정확합니다.
지정된 길이 내에서 숫자를 스마트하게 표시합니다.
아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
Display number smartly within a certain length.
final display = createDisplay(length: 8);
display(-254623933.876) // result: -254.62M
The conversion follow this rules:
It also has a JavaScript version
Add this to your package's pubspec.yaml file:
dependencies:
number_display: # latest version
Details see pub.dev
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,
);
print(display(data));
The complete configuration params are listed in the next section .
If the length overflow, the trimming rules in order are:
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:
createDisplay();
null => ''
double.nan => ''
-123456789.123456789 => '-123.457M'
'123456' => '123,456'
-1.2345e+5 => '-123,450'
With some configs:
createDisplay(
separator: false,
placeholder: '--'
);
null => '--'
123456 => '123456'
By setting the seperator and decimalPoint , numbers can be any locale form: '4.623.933,8'.
length
( 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.
decimal
( 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.
placeholder
( 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.
separator
( default: ',' )
Set the locale string separators ( 1,234,222 ), if there are rooms. Set it to null if you don't need any. Only the first char is kept.
decimalPoint
( default: '.' )
Set the locale string decimal point. Only the first char is kept.
roundingType
( default: RoundingType.round )
The rounding type when omitting decimals, enum in RoundingType.round, RoundingType.floor or RoundingType.ceil.
units
( default: ['k', 'M', 'G', 'T', 'P'] )
The digit units to use. Only the first char is kept for each unit. If the property is set to null or too short, it will fallback to the default.
의존성 목록 1 개
^1.16.8사용 목적에 따라 검색하고 개발 활동을 비교한 뒤 원본 저장소에서 요구 사항을 확인하세요.
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗