How do I get thousands separators in the results?

How do I get thousands separators in the results?

vibajajo64vibajajo64 Posts: 6Questions: 2Answers: 0

Hi, Can someone show me how to get thousand separators in the results of certain columns I have like volume and market cap?
Nothing I've tried is working. Thanks!!!

The example results can be seen at http://www.althedge.xyz/cap.html

<!DOCTYPE html><html class=''>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel='stylesheet prefetch' href='//cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css'>
<style class="cp-pen-styles"></style></head><body>

coin # Name (Symbol) Price ($) Volume($/24h) Market Cap ($) Supply 24h $.1



$(document).ready(function(){ $('#table').DataTable({ columnDefs: [ { targets: 0, visible: false}, ], order: [[1, 'asc']], }); }); var USDNPR = 1; var socket = io.connect('https://coincap.io'); //var X = document.getElementById("Crypto"); //var Y = document.getElementById("TR_" + tradeMsg.message.coin); socket.on('trades', function(tradeMsg) { var table = $('#table').DataTable(); // save the DT API instance in table var msgx = tradeMsg.message.msg; var Price = msgx.price * USDNPR; var indexes = table.rows().eq( 0 ).filter( function (rowIdx) { //check column 0 of each row for tradeMsg.message.coin return table.cell( rowIdx, 0 ).data() === tradeMsg.message.coin ? true : false; } ); if (indexes.length > 0) { // if it exists use that index to update the row table.row(indexes).data([tradeMsg.message.coin, msgx.position24, msgx.long + ' (' + msgx.short + ')', Price.toFixed(Price < 1 ? 8 : 2), (msgx.volume * USDNPR).toFixed(0), (msgx.mktcap * USDNPR).toFixed(0), msgx.supply + ' ' + msgx.short, msgx.cap24hrChange, (1 / Price).toFixed((1 / Price) < 1 ? 8 : 2) + ' ' + msgx.short]); } else { // if it doesn't exist add the row var coin = table.row.add( [tradeMsg.message.coin, msgx.position24, msgx.long + ' (' + msgx.short + ')', Price.toFixed(Price < 1 ? 8 : 2), (msgx.volume * USDNPR).toFixed(0), (msgx.mktcap * USDNPR).toFixed(0), msgx.supply + ' ' + msgx.short, msgx.cap24hrChange, (1 / Price).toFixed((1 / Price) < 1 ? 8 : 2) + ' ' + msgx.short]) .draw(false); } });

</body></html>

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,364Questions: 26Answers: 4,956

    You will want to use a number renderer. Just add it to your columnDefs for the columns you want displayed with the renderer.

    Kevin

  • vibajajo64vibajajo64 Posts: 6Questions: 2Answers: 0
    edited March 2017

    Hi, I tried this but no change. Any idea what I did wrong? Thanks!!

    $(document).ready(function(){
      $('#table').DataTable({
    
      columnDefs: [
        
        { targets: 0, visible: false},
        {
        data: 'Volume',
        render: $.fn.dataTable.render.number( ',', '.', 2, '$' )
    },
    
      ],
      order: [[1, 'asc']],
    });
    });
    
  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin
    Answer ✓

    You haven't specified a target for the object with a renderer.

    Allan

  • vibajajo64vibajajo64 Posts: 6Questions: 2Answers: 0

    Thanks Alan, that worked fine.

This discussion has been closed.