Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
77
rated 0 times [  81] [ 4]  / answers: 1 / hits: 15830  / 9 Years ago, sat, march 28, 2015, 12:00:00

I am writing a jsx file and want to format the display of numbers in a table. Here is the code for the table:



<tr>
<td>
{stringVar}
</td>
<td>
{numberVar}
</td>
</tr>


The numberVar is being printed directly; how can I display that number with C-style string formatting (I need to set precision value, add commas, and a $ character)?


More From » jquery

 Answers
109

You can use any JS expression to format the value. A popular number formatting library is http://numeraljs.com/ but there are many others of course.



As for prefixing it with $, that's just string concatenation:



{$ + numberVar}


Or, using string interpolation ES6 syntax :



{`$ ${numberVar}`}

[#67274] Thursday, March 26, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jenamackennac

Total Points: 304
Total Questions: 110
Total Answers: 107

Location: Ecuador
Member since Thu, Jun 4, 2020
4 Years ago
;