Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert numeric string to number in angular 2

I want to compare angular 2 expressions. I got array of data in numeric string from my database i need to convert this to number before give a condition with ngClass for styling. how can i convert this type. any idea?

  <td [ngClass]= "{'positive': gbh.Last > 0, 'negative': gbh.Last < 0}"> {{gbh.Last}} </td>
like image 322
U rock Avatar asked Dec 14 '22 23:12

U rock


1 Answers

This answer is the typescript way: so answer

Number('1234') // 1234
Number('9BX9') // NaN

The other answer looks like it would be for int not numbers. You are better off using the plus symbol.

var x = "32";
var y = +x; // y: number

Ref answer:

like image 67
trees_are_great Avatar answered Dec 28 '22 10:12

trees_are_great