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
Post a Comment