Why has the last number changed?

format_bank_number: function(number){
            return (number.toString()).substr(0,4)+"********"+(number.toString()).substr(-4);
        }

clipboard.png

Why did the last 9004 become 9010?

Mar.23,2021

clipboard.png
overflowed. It is better to use a string for such a long one. Bank card numbers generally do not use numeric types


.

maximum safe integer: Number.MAX_SAFE_INTEGER (es6) = Math.pow (2pm 53)

1. There is only one type of number in JS, that is, 64-bit (symbol bit of 1bit, exponential part of 11bits, and fractional part of 52bits) double-precision floating-point number. When the integer value is too large, the precision will be lost.
2. Safe integers are numbers that can be uniquely determined, that is, integers that can be uniquely determined using 64-bit binary numbers. Considering 2 ^ 53, the decimal part of the decimal part includes a total of 53 digits after being converted to the corresponding representation, and the precision is lost, so it is impossible to distinguish 2 ^ 53 from 2 ^ 53 + 1 in JS.
3, the safe integer is closely related to whether the JS can operate correctly, and the correct result of the JS operation can be guaranteed when both the Operand and the result are within the range of the safe integer.


has exceeded the maximum value. Use a string


this should be the maximum value that exceeds the number. Don't bank card numbers usually store strings? Did you send this card number to you in the background or the


you input from the user exceeds the maximum value. Convert it to a string type


.
  

all ID data should be in string mode, not even if they are all numbers. Otherwise, it is easy to have problems in dealing with it.

Menu