# @eturino/significant-diff-round 中文文档

规范地址：https://npmcn.com/package/%40eturino/significant-diff-round/

版本：1\.0\.4
npm 元数据更新时间：2022-04-05T08:27:15.644Z
中文译文更新时间：2026-11-14T00:09:05.527Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40eturino/significant-diff-round
原文对照：https://npmcn.com/package/%40eturino/significant-diff-round/?lang=original
项目主页：https://github.com/eturino/significant-diff-round.ts
源码仓库：https://github.com/eturino/significant-diff-round.ts

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：16.9 kB，19 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=10\.0
- 运行依赖：1 个
- 首次发布：2019-12-11T10:10:07.091Z
- 最新版本发布：2021-02-02T10:30:28.447Z
- 近 30 天下载量：3865（2026-10-14 至 2026-11-12，npm 官方下载统计）
- 已发布版本数：4（近 12 个月 0 个）

## 中文简介

将 2 个数字组合到足够小数点以显示它们之间的差异

## 安装

```sh
npm install @eturino/significant-diff-round
```

也可以使用：`pnpm add @eturino/significant-diff-round`、`yarn add @eturino/significant-diff-round`、`bun add @eturino/significant-diff-round`

## README

# `@eturino/significant-diff-round`

[![npm version](https://badge.fury.io/js/%40eturino%2Fsignificant-diff-round.svg)](https://badge.fury.io/js/%40eturino%2Fsignificant-diff-round) [![Build Status](https://travis-ci.org/eturino/significant-diff-round.ts.svg?branch=master)](https://travis-ci.org/eturino/significant-diff-round.ts) [![Maintainability](https://api.codeclimate.com/v1/badges/39bd6a0a6c69ffaeb6b5/maintainability)](https://codeclimate.com/github/eturino/significant-diff-round.ts/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/39bd6a0a6c69ffaeb6b5/test_coverage)](https://codeclimate.com/github/eturino/significant-diff-round.ts/test_coverage)

[类型 Doc 在此生成文件](https://eturino.github.io/significant-diff-round.ts)

[Github 重播这里](https://github.com/eturino/significant-diff-round.ts)

将 2 个数字组合到足够小数点以显示它们之间的差异

## 安装

`yarn add @eturino/significant-diff-round` 或者说 `npm install @eturino/significant-diff-round`。 。 。 .

## 使用量

两个数字,一个可选的最低精度, `significantDiffRound()` 将它们四舍五入到非常不同的精确度,这样两个四舍五入的数字就不会相等.

想法是避免四舍五入 `1.123` 财务报告和审定财务报表 `1.124` 改为 `1.12` 在这两种情况下,都失去了发现差异的能力.

如果给定的数字相同,将返回到指定的最小精度(默认为0).

结果以表单对象返回 `{ a: roundedFirstNumber, b: roundedSecondNumber, precision: numberOfDecimals }`

譬如说.

```typescript
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 }
```

## 开发、提交、版本和出版

见文件促进发展

见 [Typescript-Starter 文档](https://github.com/bitjson/typescript-starter#bump-version-update-changelog-commit--tag-release)。 。 。 .

### 提交和更改

对于犯罪,你应该使用 [`commitizen`](https://github.com/commitizen/cz-cli)

```sh
yarn global add commitizen

#commit your changes:
git cz
```

作为打字符启动文件的表示 :

此项目是用于 [常规更改日志](https://github.com/conventional-changelog/conventional-changelog) 使管理释放更容易。 见 [标准版本](https://github.com/conventional-changelog/standard-version) 关于工作流程的更多信息的文件,或 [`CHANGELOG.md`](https://npmcn.com/package/%40eturino/significant-diff-round/CHANGELOG.md) 举个例子.

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

你可以找到一个工具,比如 [**`wip`**](https://github.com/bitjson/wip) 在你准备好做出有意义的承诺之前 帮助管理正在进行的工作.

### 创建第一个版本

一旦您准备好创建第一个版本,请运行如下(注意: `reset` 具有破坏性,并将从目录中删除所有不在 git repo 中的文件.

```sh
# 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
```

之后,记住 [发布文件](https://npmcn.com/package/%40eturino/significant-diff-round/#readme-publish-the-docs)。 。 。 .

并最终将新标签推向github并发布到npm.

```sh
# 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
```

### 发布文件

```sh
yarn run doc:html && yarn run doc:publish
```

这将生成文件并在 github 页面中发布 .

### 生成一个版本

准备新版有一个单一的线条命令. 见 [一步一步以 TypeScript- Startter 发布准备脚本](https://github.com/bitjson/typescript-starter#one-step-publish-preparation-script)

```sh
# 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 是什么？

将 2 个数字组合到足够小数点以显示它们之间的差异

### 如何安装 @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 和提交记录判断。

