GithubHelp home page GithubHelp logo

yhvrwastaken / simpleformat.js Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 71 KB

A simple number formatter.

License: GNU General Public License v3.0

JavaScript 100.00%
number-formatter numbers formatter javascript

simpleformat.js's Introduction

simpleformat.js

THIS REPOSITORY IS NOW ARCHIVED. FIND OUT WHY AT THE BOTTOM.

A simple number formatter.

simpleformat.js has three functions- format.normal(), format.mixed(), and format.create().

Normal Formatting

format.normal() has two fields. number Is where you enter your variable. type Is the type of formatting you want.

Some examples:

format.normal(1.45e51, 'nor')
//OUTPUT: "1.45 Sexdecillion"

format.normal(9.82e+4, 'sci')
//OUTPUT: "9.82e4"

format.normal(15438932589032, 'eng')
//OUTPUT: "15.44e12"

Mixed Formatting

format.mixed() has four fields. number Is where you enter your variable. config.type1 Is the type used if the number is LESS than the limit. config.type2 Is the type used if the number is MORE than the limit. config.limit Decides the limit.

Some examples:

format.mixed(1.45e51, {
	limit: Infinity,
	type1: 'nor',
	type2: 'let'
})
//OUTPUT: "1.45 Sexdecillion"

format.mixed(9.82E+4, {
	limit: 5.5e4,
	type1: 'let2',
	type2: 'sci'
})
//OUTPUT: "9.82e4"

format.mixed(15438932589032, {
	limit: 78306,
	type1: "custom type",
	type2: 'eng'
})
//OUTPUT: "15.44e12"

Type Creation

format.create() has three fields. name Is the name of the notation. notation Is an array, containing the text displayed after the mantissa. type Is either sci or eng. It decides wether or not notation increments every 3 exponents (eng), or 1 (sci).

After you have created your notation, you can use it with format.normal() & format.mixed().

IMPORTANT: If the item in notation is undefined, " Unknown" is used instead.

Some examples:

format.create('custom type', [
	' A little',
	" A lot",
	' A metric ton',
	' Basically Infinity' // ' Unknown' will appear if the exponent is too large
], "sci")

format.create("short-nor", [
	" K",
	" M",
	" B",
	" T",
	" Q",
	" q",
	"I give up" // ' Unknown' will appear if the exponent is too large
], "eng")

Other

Add it to your website

You can add it to your website with this:

<script type='text/javascript' src='https://raw.githubusercontent.com/YhvrWasTaken/simpleformat.js/master/simpleformat.min.js'></script>

Or this un-minified version:

<script type='text/javascript' src='https://raw.githubusercontent.com/YhvrWasTaken/simpleformat.js/master/simpleformat.js'></script>

Or you could download it.

Format Types

Name Input Output
Scientific sci 1.00e4
Engineering eng 10.00e3
Normal nor 10.00 Thousand
2 Letters let2 1.00ab
Letters let 1.00b

Don't forget, You can create your own types!

Why did you archive this?

  1. Complete Failure.
  2. I want to make this again, but better.

simpleformat.js's People

Contributors

iamyhvr avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.