Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Converts a decimal number using fixed-point notation, avoiding the conversion from number to string of Number.toFixed, and allowing the user to choose the approximation method to be used
FixedMath is a simple utility function that converts a decimal number using fixed-point notation. Since it avoids the conversion from number to string that Number.toFixed applies, this package is particularly useful when you care about performance. It also allows the user to choose the approximation method to be used
npm install --save fixed-math
This package is written in TypeScript and is designed to be compatible with NodeJS 6+. The following types are exported:
export type Method = 'round' | 'ceil' | 'floor';
export type FixedMath = (number: number, precision?: number, method?: Method) => number;
import fixedMath, { Method, FixedMath } from 'fixed-math';
Just take a look at the signature of the method:
/**
* @param number The float number to approximate
* @param precision The number of digits (it must be an integer value) after the decimal point.
* It defaults to 2 digits.
* @param method The name of the Math.* method used as approximation.
* You can choose between 'round', 'ceil' and 'floor'.
*/
const fixedMath: FixedMath = (number, precision = 2, method = 'round');
Please take a look at the tests to check out every possible nuance and example of using this package.
Of course PRs are welcome! Before contributing, however, please be sure to run npm run test:ci
or yarn test:ci
,
in order to check if the code you wrote respects the linting conventions and if it doesn't break any test. Please
try to keep the unit test code coverage at 100%.
FAQs
Converts a decimal number using fixed-point notation, avoiding the conversion from number to string of Number.toFixed, and allowing the user to choose the approximation method to be used
The npm package fixed-math receives a total of 0 weekly downloads. As such, fixed-math popularity was classified as not popular.
We found that fixed-math demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.