A number string '5'
var num_str = '5';
How can I parseInt and let below answers correct at the same time?
{{num_str + 1}} // 6 {{num_str - 1}} // 4
parseInt can't be used in an Angular expression,
{{parseInt(num_str) - 1}}
number filter can't do add and minus,
{{num_str - 1 | number}}
If anyone have useful suggestion, I will very appreciate of you
parseInt() The parseInt() function parses a string argument and returns an integer of the specified radix (the base in mathematical numeral systems).
The parseInt method parses a value as a string and returns the first integer. A radix parameter specifies the number system to use: 2 = binary, 8 = octal, 10 = decimal, 16 = hexadecimal.
Use the parseInt() function to convert a string to a number, e.g. const num1 = parseInt(str) . The parseInt function takes the value to parse as a parameter and returns an integer parsed from the provided string.
In your controller:
$scope.num_str = parseInt(num_str, 10); // parseInt with radix
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With