
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
stround provides arbitrary precision rounding of the types supported by typical number formatting libraries (e.g. NSNumberFormatter, BigDecimal) for numbers represented as strings. The purpose is to avoid floating point errors while still working with decimal values.
$ npm install stround
$ node
> var stround = require('stround');
// Extract exports for examples below.
> var round = stround.round;
> var shift = stround.shift;
> var modes = stround.modes;
Round to integers if no precision is specified:
> round('5.025');
'5'
> round('12.8');
'13'
Round specifying a precision:
> round('1.18', 1);
'1.2'
> round('1.18', 2);
'1.18'
> round('1.68', 0);
'2'
The result will have the specified precision:
> round('1', 2);
'1.00'
> round('84.9', 2);
'84.90'
Round toward positive infinity:
> round('1.1', 0, modes.CEILING);
'2'
> round('-1.1', 0, modes.CEILING);
'-1'
Round toward negative infinity:
> round('1.8', 0, modes.FLOOR);
'1'
> round('-1.8', 0, modes.FLOOR);
'-2'
Round toward zero:
> round('1.8', 0, modes.DOWN);
'1'
> round('-1.8', 0, modes.DOWN);
'-1'
Round away from zero:
> round('1.1', 0, modes.UP);
'2'
> round('-1.1', 0, modes.UP);
'-2'
Round towards the nearest integer, or towards an even number if equidistant (this is the default):
> round('1.4', 0, modes.HALF_EVEN);
'1'
> round('1.5', 0, modes.HALF_EVEN);
'2'
> round('2.5', 0, modes.HALF_EVEN);
'2'
> round('-2.5', 0, modes.HALF_EVEN);
'-2'
> round('2.6', 0, modes.HALF_EVEN);
'3'
Round towards the nearest integer, or towards zero if equidistant:
> round('1.4', 0, modes.HALF_DOWN);
'1'
> round('1.5', 0, modes.HALF_DOWN);
'1'
> round('2.5', 0, modes.HALF_DOWN);
'2'
> round('-2.5', 0, modes.HALF_DOWN);
'-2'
> round('2.6', 0, modes.HALF_DOWN);
'3'
Round towards the nearest integer, or away from zero if equidistant:
> round('1.4', 0, modes.HALF_UP);
'1'
> round('1.5', 0, modes.HALF_UP);
'2'
> round('2.5', 0, modes.HALF_UP);
'3'
> round('-2.5', 0, modes.HALF_UP);
'-3'
> round('2.6', 0, modes.HALF_UP);
'3'
It is sometimes convenient to adjust the exponent of a number, too:
> shift('12', 2);
'1200'
> shift('123.4', -2);
'1.234'
And sometimes it's useful to keep the decimal parts in a tuple:
> shift([false, '12', '34'], 2)
[false, '1234', '']
First, install the development dependencies:
$ npm install
Then, try running the tests:
$ npm test
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)Any contributors to the master stround repository must sign the Individual Contributor License Agreement (CLA). It's a short form that covers our bases and makes sure you're eligible to contribute.
When you have a change you'd like to see in the master repository, send a pull request. Before we merge your request, we'll make sure you're in the list of people who have signed a CLA.
FAQs
Rounding methods for exact numbers using strings.
The npm package stround receives a total of 211 weekly downloads. As such, stround popularity was classified as not popular.
We found that stround demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.