Skip to content

A small javascript library to round a number to dynamic decimal points if necessary

Notifications You must be signed in to change notification settings

annsa9/round-to-decimal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

round-to-decimal

A small javascript library to round a number to dynamic decimal points

This is to overcome a case in javascript toFixed() method which always have decimal points even if number is rounded off with no decimal point. e.g. 2.toFixed(2) => 2.00

This lib. will give decimal points if necessary.

installation

npm i --save round-to-decimal

Usage

const toDecimals = require('round-to-decimal');

// OR import toDecimals from 'round-to-decimal';

const num = toDecimals(1.00, 2); // output -> 1

const num = toDecimals(2.45678, 2); // output -> 2.46

const num = toDecimals(1.13412, 3); // output -> 1.134

About

toDecimals function takes two arguments. toDecimals(value, decimalPoint)

About

A small javascript library to round a number to dynamic decimal points if necessary

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages