Skip to content

Commit 88a47fb

Browse files
committed
Formular rounding fixes
1 parent 48ab18d commit 88a47fb

File tree

3 files changed

+6
-15
lines changed

3 files changed

+6
-15
lines changed

ehr/resources/web/ehr/DataEntryUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ EHR.DataEntryUtils = new function(){
874874
}
875875
}
876876

877-
if (!amount && Ext4.isEmpty(rounding)){
877+
if (amount && !Ext4.isEmpty(rounding)){
878878
amount = EHR.Utils.roundToNearest(amount, rounding);
879879
}
880880

ehr/resources/web/ehr/utils.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -497,19 +497,9 @@ EHR.Utils = new function(){
497497
return val;
498498
}
499499

500-
var remainder = val % round;
501-
var remainderPct = remainder / round;
502-
var base = Math.floor(val / round);
503-
if (remainder === 0){
504-
return val;
505-
}
506-
//note: JS seems to handle division poorly in situations like 4 / 0.1
507-
else if (remainderPct < 0.5 || remainderPct > 0.9999){
508-
return (base * round);
509-
}
510-
else {
511-
return (base * round) + round;
512-
}
500+
let rounded = Math.round(val / round) * round;
501+
let precision = (round.toString().split('.')[1] || "").length; // Get decimal places in `round`
502+
return rounded.toFixed(precision); // toFixed handles floating point precision issues
513503
},
514504

515505
editUIButtonCore: function(schemaName, queryName, dataRegionName, paramMap, copyFilters, params){

ehr/resources/web/ehr/window/DrugAmountWindow.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,8 @@ Ext4.define('EHR.window.DrugAmountWindow', {
394394
found = true;
395395
editor = {
396396
xtype: 'ldk-numberfield',
397-
fieldName: fieldName
397+
fieldName: fieldName,
398+
decimalPrecision: 6
398399
}
399400
}
400401

0 commit comments

Comments
 (0)