calculate

calculate

wuestlwuestl Posts: 13Questions: 0Answers: 0
edited December 2013 in DataTables 1.9
Hi Allan,

i would like to show a calculation between two rows in the datatabel.

I have been testet it with mRender but my Problem ther is that with + it did not make a sum.

My Code is

"mData": "stunden",
"mRender": function ( val, type, row ) {
if ( val ) {
return (((val*60)+row.minuten)/60);
return addCommas(val, '.', ',');
}
return "";
},
"sDefaultContent": ""

when we use as example for val=1 and for row.minuten=30 then there have to be as result 1.5 but the result is now 100.5

Also i would like to replace the . with a ,

Thanks for your help
Oliver

Replies

  • wuestlwuestl Posts: 13Questions: 0Answers: 0
    Sorry, the calculation works now

    "mData": "stunden",
    "mRender": function ( val, type, row ) {
    if ( val ) {
    zeit = val*60;
    zeit = zeit*1 + row.minuten*1;
    zeit = zeit/60;
    }
    return zeit;
    },

    But i cant find how i can replace the . with ,

    zeit.replace(".",",");

    did not work.

    Thanks
    Oliver
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Its a number, so you need to cast it as a string to be able to use `replace` . Simply add a `+''` to get a string from the value and then use replace on it.

    Allan
  • wuestlwuestl Posts: 13Questions: 0Answers: 0
    Thanks for your fast respons.

    Do you have an example for me, please?

    I dont know where i have to set +''

    Best Regards
    Oliver
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    [code]
    var i = 60.3;

    i = i+'';

    i.replace( '.', ',' );
    [/code]

    You can use `toString()` as well I think. MDN will have more information about general Javascript stuff: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString

    Allan
  • wuestlwuestl Posts: 13Questions: 0Answers: 0
    Ok, it works fine.

    Thank you so much for your help and your patience with me ;)

    Best Regards
    Oliver
This discussion has been closed.