number format

number format

bigtiger0905bigtiger0905 Posts: 1Questions: 1Answers: 0

please tell me how to render column with number like this:
10,000,01 => 10,000,01
10,000,10 => 10,000,1
10,000 => 10,000
thanks!

This question has accepted answers - jump to:

Answers

  • rf1234rf1234 Posts: 2,939Questions: 87Answers: 415
    Answer ✓

    those are not numbers I guess. The decimal point is a comma and the thousand separator is a comma, too. How is that supposed to work? And in what language do you want to render your numbers? Javascript? PHP?

    All you would need to do to achieve the above is to check whether the third last character is a comma and the last character is a 0. If so remove the last character. If you do this lines 1 and 3 remain unchanged only line 2 is modified.

    I tried this in JavaScript:

    var num = ['10,000,01', '10,000,10', '10,000'];
    var modified = [];
    num.forEach(function(entry) {
        var lastThree = entry.substr(entry.length - 3); // => ",10"
        if ( lastThree.substr(0, 1) === ',' ) {
            if ( lastThree.substr(2, 1)  === '0' ) {
                entry = entry.substr(0, entry.length - 1);
            }
        }
        modified.push(entry);
    });
    
    modified.forEach(function(entry) {
      console.log(entry);
    });
    
    

    Result was:

  • colincolin Posts: 15,237Questions: 1Answers: 2,598
    Answer ✓

    Hi @bigtiger0905 ,

    That's a non-standard render, so you'll need to create your own in columns.render,

    Cheers,

    Colin

This discussion has been closed.