Skip to content

Commit

Permalink
fix: fix hours float addition
Browse files Browse the repository at this point in the history
7 + 6.97 = 13.969 repeating in JS because of floating point arithmetic
we round numbers to two decimal places
  • Loading branch information
phette23 committed Sep 11, 2024
1 parent 47e979a commit 381999f
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions mod_data/timetracker/timetracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function timecount() {
document.querySelectorAll('.js-data-row').forEach(row => {
let name = row.querySelector('.js-data-cell .name').innerText
let hours = parseFloat(row.querySelector('.js-data-cell .hours').innerText)
counts[name] = (counts[name] || 0) + hours
counts[name] = parseFloat(((counts[name] || 0) + hours).toFixed(2))
})

// add counts to page
Expand Down Expand Up @@ -94,7 +94,6 @@ function exposeCSVExport(target) {
if (document.createElement("a").download !== undefined) { // feature detection
// Browsers that support HTML5 download attribute
let url = URL.createObjectURL(makeCSVBlob())
// TODO prepend student name to filename? we can't determine if user is student or teacher though
target.innerHTML = `<p><a class="btn btn-primary" href="${url}" download="timesheet.csv">Download CSV</a></p><p>As with the totals, this exports <b>only the entries visible in the list above</b> so use the "Entries per page" and "Search" settings to ensure you get all the data you need.</p>`
} else {
// Browsers that don't support HTML5 download attribute
Expand Down

0 comments on commit 381999f

Please sign in to comment.