fix rounded method two decimal places
This commit is contained in:
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
function getRoundedMethod(number = 0.0) {
|
||||
const numberString = (Math.floor(number * 100) / 100).toFixed(2);
|
||||
let rounded = numberString.slice(0, -1);
|
||||
const lastDigit = parseInt(numberString.slice(-1), 10);
|
||||
|
||||
if (lastDigit >= 0 && lastDigit <= 2) {
|
||||
rounded = rounded.replace(',', ''); // Remove commas
|
||||
return parseFloat(rounded);
|
||||
} else if (lastDigit >= 3 && lastDigit <= 7) {
|
||||
rounded += '5';
|
||||
rounded = rounded.replace(',', ''); // Remove commas
|
||||
return parseFloat(rounded);
|
||||
} else {
|
||||
return customRound(number);
|
||||
}
|
||||
}
|
||||
function customRound(number) {
|
||||
const precision = 1; // Round to one decimal place
|
||||
const factor = Math.pow(10, precision);
|
||||
return Math.ceil(number * factor) / factor;
|
||||
}
|
||||
Reference in New Issue
Block a user