Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ehr/resources/web/ehr/DataEntryUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ EHR.DataEntryUtils = new function(){
}
}

if (!amount && Ext4.isEmpty(rounding)){
if (amount && !Ext4.isEmpty(rounding)){
amount = EHR.Utils.roundToNearest(amount, rounding);
}

Expand Down
16 changes: 3 additions & 13 deletions ehr/resources/web/ehr/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,19 +497,9 @@ EHR.Utils = new function(){
return val;
}

var remainder = val % round;
var remainderPct = remainder / round;
var base = Math.floor(val / round);
if (remainder === 0){
return val;
}
//note: JS seems to handle division poorly in situations like 4 / 0.1
else if (remainderPct < 0.5 || remainderPct > 0.9999){
return (base * round);
}
else {
return (base * round) + round;
}
let rounded = Math.round(val / round) * round;
let precision = (round.toString().split('.')[1] || "").length; // Get decimal places in `round`
return rounded.toFixed(precision); // toFixed handles floating point precision issues
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, good to know about toFixed().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

floating point is the worst

},

editUIButtonCore: function(schemaName, queryName, dataRegionName, paramMap, copyFilters, params){
Expand Down
3 changes: 2 additions & 1 deletion ehr/resources/web/ehr/window/DrugAmountWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,8 @@ Ext4.define('EHR.window.DrugAmountWindow', {
found = true;
editor = {
xtype: 'ldk-numberfield',
fieldName: fieldName
fieldName: fieldName,
decimalPrecision: 6
}
}

Expand Down