-
Notifications
You must be signed in to change notification settings - Fork 324
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
Support string #34
Support string #34
Conversation
这个test命令是跑测试用例使用的吗,我直接拉的代码,没有任何修改,yarn了之后,yarn test就会报这个错,是什么原因呢?然后我加了个test1:“ava”,是可以跑通测试用例的 |
Codecov Report
@@ Coverage Diff @@
## master #34 +/- ##
===========================================
- Coverage 96.77% 76.31% -20.46%
===========================================
Files 1 1
Lines 93 76 -17
Branches 27 17 -10
===========================================
- Hits 90 58 -32
- Misses 3 18 +15
Continue to review full report at Codecov.
|
不太理解支持string的必要性 |
是可以转换,我是这么理解的,因为有很多数据来源是后端传值或者input组件读到的,那使用库的时候还需要给每个数都Number转一下呢plus(Number(a),Number(b))这么用起来感觉不太顺手,不如直接plus(a,b),因为我看每个函数的处理都toString了,其实也是转成字符串然后把小数点去掉,使用整数进行运算再转换回来的
…------------------ 原始邮件 ------------------
发件人: "Cam Song"<notifications@github.com>;
发送时间: 2020年6月17日(星期三) 中午11:12
收件人: "nefe/number-precision"<number-precision@noreply.github.com>;
抄送: "霖~雨℃"<1534946959@qq.com>;"Author"<author@noreply.github.com>;
主题: Re: [nefe/number-precision] Support string (#34)
不太理解支持string的必要性 +'123' 就可以把 string 转成 number 来处理
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
大牛好,还是想问问是否可以考虑支持string类型的输入 |
@@ -7,31 +8,31 @@ | |||
* 把错误的数据转正 | |||
* strip(0.09999999999999998)=0.1 | |||
*/ | |||
function strip(num: number, precision = 12): number { | |||
return +parseFloat(num.toPrecision(precision)); | |||
function strip(num: numType, precision = 15): number { |
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.
改成15的原因是什么?
当时是这个测试用例没过
而且这两个数的toSting结果不一样
1.2345678912345e10直接走的 Number(num.toString().replace(".", "")) 输出是12345678912345
'1.2345678912345e10' 走的 strip 函数
toPrecision(12)就不行了,后来我想改成16,但是 0.09999999999999998 这个数不行,我就改成了15
其实还想请教一下大牛为什么是12,不太明白12是怎么得出来的
…------------------ 原始邮件 ------------------
发件人: "Cam Song"<notifications@github.com>;
发送时间: 2020年6月18日(星期四) 晚上6:28
收件人: "nefe/number-precision"<number-precision@noreply.github.com>;
抄送: "霖~雨℃"<1534946959@qq.com>;"Author"<author@noreply.github.com>;
主题: Re: [nefe/number-precision] Support string (#34)
@camsong commented on this pull request.
In src/index.ts:
> @@ -7,31 +8,31 @@ * 把错误的数据转正 * strip(0.09999999999999998)=0.1 */ -function strip(num: number, precision = 12): number { - return +parseFloat(num.toPrecision(precision)); +function strip(num: numType, precision = 15): number {
改成15的原因是什么?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
这个库不能确保一定能解决浮点数问题,12 是尝试出来的。Thanks for your contribution |
大部分场景都是可以满足的,十分感谢,16位数已经到千万亿级别了,很少会触及到
…------------------ 原始邮件 ------------------
发件人: "Cam Song"<notifications@github.com>;
发送时间: 2020年6月24日(星期三) 下午3:31
收件人: "nefe/number-precision"<number-precision@noreply.github.com>;
抄送: "霖~雨℃"<1534946959@qq.com>;"Author"<author@noreply.github.com>;
主题: Re: [nefe/number-precision] Support string (#34)
这个库不能确保一定能解决浮点数问题,12 是尝试出来的。Thanks for your contribution
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
支持string类型的运算,添加yarn test1运行单元测试的命令