fix: shorten_number
Before, `shorten_number(1234.5678, "Germany", 5)` wrongly returned `"1 K"`. Now it correctly returns `"1235"`, which is less than five digits.
This commit is contained in:
parent
c146ea24b6
commit
30756e27d4
1 changed files with 10 additions and 1 deletions
|
|
@ -1339,10 +1339,19 @@ Object.assign(frappe.utils, {
|
|||
|
||||
// return number if total digits is lesser than min_length
|
||||
const len = String(number).match(/\d/g).length;
|
||||
if (len < min_length) return number.toString();
|
||||
if (len < min_length) {
|
||||
return number.toString();
|
||||
}
|
||||
|
||||
const number_system = this.get_number_system(country);
|
||||
let x = Math.abs(Math.round(number));
|
||||
|
||||
// if rounding was sufficient to get below min_length, return the rounded number
|
||||
const x_string = x.toString();
|
||||
if (x_string.length < min_length) {
|
||||
return x_string;
|
||||
}
|
||||
|
||||
for (const map of number_system) {
|
||||
if (x >= map.divisor) {
|
||||
let result = number / map.divisor;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue