@eturino/significant-diff-round
将 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 }
譬如说.
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 文档。 。 。 .
提交和更改
对于犯罪,你应该使用 commitizen
yarn global add commitizen
#commit your changes:
git cz
作为打字符启动文件的表示 :
此项目是用于 常规更改日志 使管理释放更容易。 见 标准版本 关于工作流程的更多信息的文件,或 CHANGELOG.md 举个例子.
# bump package.json version, update CHANGELOG.md, git tag the release
yarn run version
你可以找到一个工具,比如 wip 在你准备好做出有意义的承诺之前 帮助管理正在进行的工作.
创建第一个版本
一旦您准备好创建第一个版本,请运行如下(注意: reset 具有破坏性,并将从目录中删除所有不在 git repo 中的文件.
# 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
之后,记住 发布文件。 。 。 .
并最终将新标签推向github并发布到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
发布文件
yarn run doc:html && yarn run doc:publish
这将生成文件并在 github 页面中发布 .
生成一个版本
准备新版有一个单一的线条命令. 见 一步一步以 TypeScript- Startter 发布准备脚本
# 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