javascript - Format number in jsx React component -


this question has answer here:

i writing jsx file , want format display of numbers in table. here code table:

<tr>   <td>     {stringvar}   </td>   <td>     {numbervar}   </td> </tr> 

the numbervar being printed directly; how can display number c-style string formatting (i need set precision value, add commas, , $ character)?

you can use js expression format value. popular number formatting library http://numeraljs.com/ there many others of course.

as prefixing $, that's string concatenation:

{"$" + numbervar} 

or, using string interpolation es6 syntax :

{`$ ${numbervar}`} 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -