Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(module:input-number): support nzPrecisionMode mode #4185

Merged
merged 4 commits into from
Feb 9, 2020

Conversation

renxia
Copy link
Contributor

@renxia renxia commented Sep 19, 2019

close #4173

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Application (the showcase website) / infrastructure changes
[ ] Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

@codecov
Copy link

codecov bot commented Sep 19, 2019

Codecov Report

Merging #4185 into master will decrease coverage by 0.1%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4185      +/-   ##
==========================================
- Coverage   92.27%   92.17%   -0.11%     
==========================================
  Files         517      520       +3     
  Lines       10962    11025      +63     
  Branches     1985     2000      +15     
==========================================
+ Hits        10115    10162      +47     
- Misses        422      431       +9     
- Partials      425      432       +7
Impacted Files Coverage Δ
...mponents/input-number/nz-input-number.component.ts 97.23% <100%> (+0.14%) ⬆️
components/core/logger/logger.ts 38.88% <0%> (-11.12%) ⬇️
components/select/nz-option-container.component.ts 88.88% <0%> (-7.99%) ⬇️
...mponents/select/nz-select-top-control.component.ts 93.75% <0%> (-6.25%) ⬇️
components/i18n/date-helper.service.ts 68% <0%> (-4%) ⬇️
components/affix/nz-affix.component.ts 92.15% <0%> (-3.94%) ⬇️
components/select/nz-select.component.ts 93.07% <0%> (-3.2%) ⬇️
components/tag/nz-tag.component.ts 96.87% <0%> (-3.13%) ⬇️
components/dropdown/nz-dropdown.directive.ts 83.94% <0%> (-2.32%) ⬇️
components/core/time/candy-date.ts 85.26% <0%> (-1.56%) ⬇️
... and 68 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a9900ed...b3fca73. Read the comment docs.

@netlify
Copy link

netlify bot commented Sep 19, 2019

Deploy preview for ng-zorro-master ready!

Built with commit b3fca73

https://deploy-preview-4185--ng-zorro-master.netlify.com

@@ -37,6 +37,7 @@ import { NzInputNumberModule } from 'ng-zorro-antd/input-number';
| `[nzFormatter]` | 指定输入框展示值的格式 | `(value: number \| string) => string \| number` | - |
| `[nzParser]` | 指定从 nzFormatter 里转换回数字的方式,和 nzFormatter 搭配使用 | `(value: string) => string \| number` | - |
| `[nzPrecision]` | 数值精度 | `number` | - |
| `[nzPrecisionMode]` | 数值精度的取值方式 | `round|floor` | `round` |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

还有 ceiling。这个参数能不能支持一个函数,让用户自定义呢?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

考虑的很周到,加一个 ceil 我觉得是可以的,自定义函数也可以考虑

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

考虑了一下,叫 floor/round/ceil 都不太合理,这里默认的目的只是截断(cut off)或四舍五入(toFixed),如果有更复杂的逻辑则用自定义函数就行了

if (isNotNil(this.nzPrecision)) {
return Number(Number(num).toFixed(this.nzPrecision));
const numStr = String(num);
if (~numStr.indexOf('.')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不建议使用位操作符号

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可否列举一下原因或经验,让我等学习一下

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@vthinkxie vthinkxie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议增加 nzPrecisionFunc 函数,默认为Number(Number(num).toFixed(this.nzPrecision))
用户可以自定义就ok了

@renxia
Copy link
Contributor Author

renxia commented Oct 14, 2019

建议增加 nzPrecisionFunc 函数,默认为Number(Number(num).toFixed(this.nzPrecision))
用户可以自定义就ok了

这里的目的就是希望简单配置可截断处理,nzPrecisionFunc 这样的逻辑并不是很实用。

对于大部分需求来说,四舍五入就足够了。在对钱券计算要求非常高的情况下,才会有截断这种需求。其他类型的需求就更小了。

简单来说,如果 nzPrecisionFunc 能用得上,这个参数的意义就聊胜于无或没什么意义,因为在 nzBlurngModelChange 中去实现复杂的自定义处理逻辑就完全足够了。

@vthinkxie vthinkxie changed the title feat(module:input-number): 增加 nzPrecisionMode 参数,支持数值精度使用截位方式取值 feat(module:input-number): support nzPrecisionMode mode Feb 9, 2020
@vthinkxie vthinkxie merged commit bfe089f into NG-ZORRO:master Feb 9, 2020
Ricbet pushed a commit to Ricbet/ng-zorro-antd that referenced this pull request Apr 9, 2020
* feat(module:input-number): 增加 `nzPrecisionMode` 参数,支持数值精度使用截位方式取值

close NG-ZORRO#4173

* fix(module:input-number): fix for precision demo

* fix(module:input-number): fix for precision unit

* refactor(module:input-number):  支持 `nzPrecisionMode` 参数为自定义函数
@hsuanxyz hsuanxyz mentioned this pull request Apr 15, 2020
hsuanxyz pushed a commit to hsuanxyz/ng-zorro-antd that referenced this pull request Aug 5, 2020
* feat(module:input-number): 增加 `nzPrecisionMode` 参数,支持数值精度使用截位方式取值

close NG-ZORRO#4173

* fix(module:input-number): fix for precision demo

* fix(module:input-number): fix for precision unit

* refactor(module:input-number):  支持 `nzPrecisionMode` 参数为自定义函数
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

支持 InputNumber 组件 nzPrecision 精度的处理方式为四舍五入或截断
3 participants