![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
number-display
Advanced tools
Display number smartly within a certain length.
const display = createDisplay({ length: 8 });
display(-254623933.876) // result: -254.62M
The conversion follow this rules:
length
.It also has a Dart version .
yarn add number-display
We have built-in types, so Typescript is supported
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 createDisplay from 'number-display';
const display = createDisplay({
length: 8,
decimal: 0,
});
<div>{display(data)}</div>
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 error.Conversion examples:
createDisplay();
null => ''
NaN => ''
{} => ''
-123456789.123456789 => '-123.457M'
'123456' => '123,456'
-1.2345e+5 => '-123,450'
Note that usually we will try to convert the number-like string input value
to real number , say '-123', but some special form will be regarded as text like 'NaN', '-1.2345e+5':
'-1.2345e+5' => '-1.2345e+'
'NaN' => 'NaN'
With some configs:
createDisplay({
allowText: false,
separator: false,
placeholder: '--'
});
null => '--'
'abcdefghijklmn' => 'abcdefghi'
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 be longer then 5 so that any number can display ( say -123000 ) after trim, or you may get a console warning and length overflow.
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.
allowText
( default: false )
Allow Text ( String that cant convert to number) as input and result. It will be sliced within length param. If false , result of text will be placeholder. Note that some special form will be regarded as text like 'NaN', '-1.2345e+5'.
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: 'round' )
The rounding type when omitting decimals, enum in 'round', 'floor' or '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.
FAQs
Display number smartly within a certain length.
The npm package number-display receives a total of 37 weekly downloads. As such, number-display popularity was classified as not popular.
We found that number-display demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.