@eturino/significant-diff-round

中文文档
1.0.4发布于 2021/02/02MITTypeScriptESM + CJS近 30 天下载 3865

util to round 2 numbers to the enough number of decimals to show the difference between them

原始使用文档
文档目录7 节
  1. Installation
  2. Usage
  3. Development, Commits, versioning and publishing
  4. Commits and CHANGELOG
  5. Creating the first version
  6. Publish the Docs
  7. Generate a version

@eturino/significant-diff-round

npm version Build Status Maintainability Test Coverage

TypeDoc generated docs in here

Github repo here

util to round 2 numbers to the enough number of decimals to show the difference between them

Installation

yarn add @eturino/significant-diff-round or npm install @eturino/significant-diff-round.

Usage

Given 2 numbers, an an optional minimum precision, significantDiffRound() will round them to the precision needed to be significantly different, so that the 2 rounded numbers are not equal.

The idea is to avoid rounding 1.123 and 1.124 to 1.12 in both cases, loosing the ability to spot the difference.

If the given numbers are the same, they will be returned rounded to the minimum precision specified (default 0).

The results are returned in an object of the form { a: roundedFirstNumber, b: roundedSecondNumber, precision: numberOfDecimals }

e.g.

import significantDiffRound from "@eturino/significant-diff-round";

// same number
significantDiffRound(1.123, 1.123); // => { a: 1, b: 1, precision: 0 }
significantDiffRound(1.123, 1.123, 2); // => { a: 1.12, b: 1.12, precision: 2 }

// numbers diff in int part
significantDiffRound(1.123, 2.321); // => { a: 1, b: 2, precision: 0 }
significantDiffRound(1.123, 2.321, 1); // => { a: 1.1, b: 2.3, precision: 1 }

// numbers diff in decimal part
significantDiffRound(1.123, 1.21); // => { a: 1.1, b: 1.2, precision: 1 }
significantDiffRound(1.123, 1.21, 2); // => { a: 1.12, b: 1.21, precision: 2 }
significantDiffRound(1.1234111, 1.12323313); // => { a: 1.1234, b: 1.1232, precision: 4 }
significantDiffRound(1.12321414, 1.1236531541); // => { a: 1.123, b: 1.124, precision: 3 }

// max precision (depends on Number.EPSILON)
significantDiffRound(1, 0.9999999999999998); // => { a: 1, b: 0.9999999999999998, precision: 16 }

Development, Commits, versioning and publishing

See documentation for development

See The Typescript-Starter docs.

Commits and CHANGELOG

For commits, you should use commitizen

yarn global add commitizen

#commit your changes:
git cz

As typescript-starter docs state:

This project is tooled for conventional changelog to make managing releases easier. See the standard-version documentation for more information on the workflow, or CHANGELOG.md for an example.

# bump package.json version, update CHANGELOG.md, git tag the release
yarn run version

You may find a tool like wip helpful for managing work in progress before you're ready to create a meaningful commit.

Creating the first version

Once you are ready to create the first version, run the following (note that reset is destructive and will remove all files not in the git repo from the directory).

# Reset the repo to the latest commit and build everything
yarn run reset && yarn run test && yarn run doc:html

# Then version it with standard-version options. e.g.:
# don't bump package.json version
yarn run version -- --first-release

# Other popular options include:

# PGP sign it:
# $ yarn run version -- --sign

# alpha release:
# $ yarn run version -- --prerelease alpha

And after that, remember to publish the docs.

And finally push the new tags to github and publish the package to npm.

# Push to git
git push --follow-tags origin master

# Publish to NPM (allowing public access, required if the package name is namespaced like `@somewhere/some-lib`)
yarn publish --access public

Publish the Docs

yarn run doc:html && yarn run doc:publish

This will generate the docs and publish them in github pages.

Generate a version

There is a single yarn command for preparing a new release. See One-step publish preparation script in TypeScript-Starter

# Prepare a standard release
yarn prepare-release

# Push to git
git push --follow-tags origin master

# Publish to NPM (allowing public access, required if the package name is namespaced like `@somewhere/some-lib`)
yarn publish --access public

版本与发布记录

@eturino/significant-diff-round 共发布 4 个版本,首次发布于 2019/12/11;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.4latest2021/02/025 年前
1.0.22020/05/136 年前
1.0.12020/04/156 年前
1.0.02019/12/116 年前

关于 @eturino/significant-diff-round 的常见问题

@eturino/significant-diff-round 是什么?

util to round 2 numbers to the enough number of decimals to show the difference between them

如何安装 @eturino/significant-diff-round?

在项目目录运行 npm install @eturino/significant-diff-round,或使用 pnpm add / yarn add / bun add。

@eturino/significant-diff-round 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@eturino/significant-diff-round 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@eturino/significant-diff-round 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=10.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@eturino/significant-diff-round 可以商用吗?

@eturino/significant-diff-round 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@eturino/significant-diff-round 的下载量有多少?

根据 npm 官方下载统计,@eturino/significant-diff-round 在 2026/10/14 – 2026/11/12 这 30 天内被下载 3,865 次,日均约 129 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@eturino/significant-diff-round 还在维护吗?

最新版本 1.0.4 发布于 2021/02/02(5 年前);至今共发布 4 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/12/11。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。