fix(core): Fix decimal pipe floating point formatting bug#53730
fix(core): Fix decimal pipe floating point formatting bug#53730injae-kim wants to merge 3 commits intoangular:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
75c4a1c to
b978193
Compare
b978193 to
9d5d49b
Compare
There was a problem hiding this comment.
The condition doesn't cover every non valid string, we should likely rely on strToNumber to throw.
There was a problem hiding this comment.
if (typeof value === 'string' && value.includes('.') && strToNumber(value)) {
const parts = value.split('.');
const integerPart = parts[0];
const fractionPart = `0.${parts[1]}`;
..
Hmm you mean calling strToNumber(value) inside of if(..)?
Or can you give some example code? 🙇
Cause parts is array of string, we can't pass it to strToNumber(string) directly 🤔
There was a problem hiding this comment.
We can either call strToNumber() or probably better, extract the portion we'd like to reuse in a function :
function isStringNumber(value: number|string): boolean {
return typeof value === 'string' && !isNaN(Number(value) - parseFloat(value))
}
There was a problem hiding this comment.
aha~ I understood. isStringNumber looks much better! thanks for nice suggestion 👍
edc5ec6 to
940e8d5
Compare
fix(core): Fix decimal pipe floating point formatting bug Address `JeanMeche`'s comments Extract duplicated codes to isStringNumber()
940e8d5 to
92d36d0
Compare
|
I need this feature and ready to update PR, so waiting your awesome reviews~ thanks! 😃 |
|
Per #47809
|
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
PR Type
What is the current behavior?
angular/packages/common/src/pipes/number_pipe.ts
Lines 104 to 105 in d315e2c
decimal_pipeparse string to number first and then apply formating'123456789.123456789'string to number, some digit on fraction part is lost due to javascript floating point limitationWhat is the new behavior?
Does this PR introduce a breaking change?