-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
Deploy preview for ng-zorro-master ready! Built with commit b3fca73 |
@@ -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` | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
还有 ceiling。这个参数能不能支持一个函数,让用户自定义呢?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
考虑的很周到,加一个 ceil 我觉得是可以的,自定义函数也可以考虑
There was a problem hiding this comment.
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('.')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不建议使用位操作符号
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可否列举一下原因或经验,让我等学习一下
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this 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了
这里的目的就是希望简单配置可截断处理,nzPrecisionFunc 这样的逻辑并不是很实用。 对于大部分需求来说,四舍五入就足够了。在对钱券计算要求非常高的情况下,才会有截断这种需求。其他类型的需求就更小了。 简单来说,如果 |
nzPrecisionMode
参数,支持数值精度使用截位方式取值* 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` 参数为自定义函数
* 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` 参数为自定义函数
close #4173
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information