@writetome51/get-fixed-float
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

getFixedFloat(
      number,
      numDigitsAfterDecimal
): string

Returns number with a decimal and exact numDigitsAfterDecimal.
If number already has more than numDigitsAfterDecimal, it will be
rounded to the last required digit after the decimal.
The algorithm prevents cumulative rounding errors.

Examples

getFixedFloat(101.975, 3); // --> '101.975'

getFixedFloat(-10.7754, 1); // --> '-10.8'

getFixedFloat(101.965, 2); // --> '101.96'

getFixedFloat(101.975, 2); // --> '101.98'

getFixedFloat(9, 2); // --> '9.00'

getFixedFloat(-100.9754, 5)); // -->  '-100.97540'

getFixedFloat(10.9754, 1); // --> '11.0'

Installation

npm i @writetome51/get-fixed-float

Loading

import {getFixedFloat}  from '@writetome51/get-fixed-float';

Package Sidebar

Install

npm i @writetome51/get-fixed-float

Weekly Downloads

0

Version

2.0.1

License

MIT

Unpacked Size

3.31 kB

Total Files

5

Last publish

Collaborators

  • writetome51