Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I parse String to Int in an Angular expression?

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

like image 639
Chen-Tsu Lin Avatar asked Jan 28 '14 06:01

Chen-Tsu Lin


People also ask

Which function is used to parse a string to int?

parseInt() The parseInt() function parses a string argument and returns an integer of the specified radix (the base in mathematical numeral systems).

What is parseInt in angular?

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.

How do you use parseInt in typescript?

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.


1 Answers

In your controller:

$scope.num_str = parseInt(num_str, 10);  // parseInt with radix 
like image 53
rg88 Avatar answered Sep 30 '22 09:09

rg88