Skip to content

derion-io/move-decimal-point

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

move-decimal-point

Move the decimal point of numbers to the right or left, operating on the number as a string. In other words, a lightweight way to perform accurate division/multiplication with powers of 10 without needing a library for arbitrary-precision decimal arithmetic.

Install

npm install move-decimal-point

Use

var move_decimal = require('move-decimal-point');

// Move to the right
move_decimal('123.456', 1); // '1234.56'
move_decimal('123.456', 3); // '123456'
move_decimal('123.456', 5); // '12345600'

// Move to the left
move_decimal('123.456', -1); // '12.3456'
move_decimal('123.456', -3); // '0.123456'
move_decimal('123.456', -5); // '0.00123456'

Test

git clone [email protected]:shesek/move-decimal-point.git &&
cd move-decimal-point &&
npm install &&
npm test

License

MIT

About

Move the decimal point of string numbers

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • CoffeeScript 100.0%