extract fraction value

extract fraction value

BhavinBhattBhavinBhatt Posts: 27Questions: 9Answers: 0

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

implemented row grouping with totals.

I want to extract fraction value of each row and multiply that value with 0.6.

Ex:
col value: 38.78

result should be: 38.46 (0.78 * 0.6).

How to do this?

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923
    Answer ✓

    Not sure exactly what you are looking for but this example shows how to aggregate row data by iterating all the rows(the rows parameter) in the group. Change the Javascript to calculate the data the way you want.

    If you still need help with this please build a simple running test case with an example set of your data so we can help structure your code.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • rf1234rf1234 Posts: 2,950Questions: 87Answers: 416
    edited August 2020 Answer ✓

    Do you really want 38.46? I mean .78 * .6 is .47 rounded and not .46.

    This code alerts 0.47 ("dec") and 38.47 ("newVal"):

    var val = 38.78;
    var intNum = Math.trunc(val);
    var dec =  Math.round((parseFloat(val) - intNum) * 0.6 * 100  ) / 100;
    alert (dec); 
    var newVal = intNum + dec;
    alert (newVal); 
    

    This code alerts 0.46 ("dec") and 38.46 ("newVal"):

    var val = 38.78;
    var intNum = Math.trunc(val);
    var dec =  Math.floor((parseFloat(val) - intNum) * 0.6 * 100  ) / 100;
    alert (dec); 
    var newVal = intNum + dec;
    alert (newVal); 
    
  • BhavinBhattBhavinBhatt Posts: 27Questions: 9Answers: 0

    Thanks to all of you,

    I've developed simple JS function and call inside rowGroup...

    Regards,
    ßhavin.

This discussion has been closed.