Skip to content

bolorundurowb/millify-dotnet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

millify-dotnet

Coverage Status License: MIT NuGet Badge

A dotnet library to convert long numbers to pretty, human-readable strings.

This library is heavily inspired by the millify NodeJS library.

Install

Get it on nuget

Package Manager

Install-Package millify

.NET CLI

> dotnet add package millify

PackageReference

<PackageReference Include="millify" />

Usage

Add the following import to the top of your csharp code file or your global Usings.cs file:

using MillifyDotnet;

To shorten any number, call the Shorten method on the Millify class.

var result = Millify.Shorten(2500);
// 2.5K

result = Millify.Shorten(1024000);
// 1.0M

The MillifyOptions class offers configurable options for the output. Further details as well as defaults can be seen in the table below.

var options = new MillifyOptions(precision: 3, lowercase: true);
var result = Millify.Shorten(1024000, options);
// 1.024m

options = new MillifyOptions(space: true, units: new[] {"B", "KB", "MB", "GB", "TB"});
result = Millify.Shorten(1440000, options);
// 1.44 MB

Options

Name Type Default Description
Precision number 1 Number of decimal places to use
Lowercase boolean false Use lowercase abbreviations
SpaceBeforeUnit boolean false Add a space between number and abbreviation
units Array<string> ['', 'K', 'M', 'B', 'T', 'P', 'E'] Optional custom unit abbreviations

About

A dotnet library to convert long numbers to pretty, human-readable strings.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages