I have a huge table with numbers and other data. I want to color the large numbers based on their value in decimal, hundreds, thousands, and millions.
For example:
<tr>
<td class="numColour">20,000,365.00 ISK</td>
<td class="numColour">2,467,218,928.46 ISK</td>
<td class="numColour">498,356.65 ISK</td>
</tr>
All the numbers are in a TD class=numColour. I want to format them like this:
<tr>
<td class="numColour"><span class="red">20</span>,<span class="blue">000</span>,<span class="green">365</span>.<span class="white">00</span> ISK</td>
<td class="numColour"><span class="yellow">2</span>,<span class="red">467</span>,<span class="blue">218</span>,<span class="green">928</span>.<span class=white">46</span> ISK</td>
<td class="numColour"><span class="blue">498</span>,<span class="green">356</span>.<span class="white">65</span> ISK</td>
</tr>
I initially added spans to the numbers like this:
$('.numColour').each(function(){
var tempVal = $(this).html();
tempVal = tempVal.replace(' ISK', '</span> ISK').replace('.', '</span>.<span>').replace(/,/g, '</span>,<span>');
tempVal = "<span>" + tempVal;
$(this).html(tempVal);
});
But I'm having trouble figuring out how to add the classes based on the number value. For instance, fractions should be white, hundreds should be green, thousands should be blue, millions should be red, and hundreds of millions should be yellow.
I'm stuck. Any help would be greatly appreciated. Thank you.