JSPM

round-to-decimal

1.0.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q43015F
  • License ISC

A small javascript library to convert value to fixed decimal points if necessary

Package Exports

  • round-to-decimal

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (round-to-decimal) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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)