esoftplay 0.0.156 → 0.0.157
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/modules/lib/utils.ts +34 -18
- package/package.json +1 -1
package/modules/lib/utils.ts
CHANGED
|
@@ -131,26 +131,42 @@ export default {
|
|
|
131
131
|
},
|
|
132
132
|
/** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/utils.md#money) untuk melihat dokumentasi*/
|
|
133
133
|
money(value: string | number, currency?: string): string {
|
|
134
|
-
if (!value) value = 0
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
const locale = LibLocale.state().get()
|
|
134
|
+
if (!value) value = 0;
|
|
135
|
+
|
|
136
|
+
let numberValue = typeof value === "number" ? value : parseFloat(value);
|
|
137
|
+
|
|
138
|
+
// Dapatkan locale & tentukan currency
|
|
139
|
+
const locale = LibLocale.state().get();
|
|
142
140
|
if (!currency) {
|
|
143
|
-
|
|
144
|
-
currency = "Rp"
|
|
145
|
-
} else {
|
|
146
|
-
currency = "IDR"
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
if (typeof val === "number") {
|
|
150
|
-
return currency?.replace?.(/\./g, "") + " " + String(val)?.replace?.(/,/g, ".");
|
|
151
|
-
} else {
|
|
152
|
-
return currency?.replace?.(/\./g, "") + " " + val?.replace?.(/,/g, ".");
|
|
141
|
+
currency = locale === "id" ? "Rp" : "IDR";
|
|
153
142
|
}
|
|
143
|
+
|
|
144
|
+
// Cek apakah IDR/Rp → format Indonesia
|
|
145
|
+
const isIDR = currency === "IDR" || currency === "Rp";
|
|
146
|
+
|
|
147
|
+
// Jika IDR, bulatkan angkanya
|
|
148
|
+
numberValue = isIDR ? Math.round(numberValue) : numberValue;
|
|
149
|
+
|
|
150
|
+
// Format dasar
|
|
151
|
+
const isInteger = Number.isInteger(numberValue);
|
|
152
|
+
let val = numberValue.toFixed(isIDR ? 0 : isInteger ? 0 : 2);
|
|
153
|
+
|
|
154
|
+
// Pisahkan jadi integer dan decimal
|
|
155
|
+
const parts = val.split(".");
|
|
156
|
+
let integerPart = parts[0];
|
|
157
|
+
const decimalPart = parts[1] || "";
|
|
158
|
+
|
|
159
|
+
// Format ribuan
|
|
160
|
+
integerPart = isIDR
|
|
161
|
+
? integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ".") // ribuan titik
|
|
162
|
+
: integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ","); // ribuan koma
|
|
163
|
+
|
|
164
|
+
// Gabungkan dengan desimal sesuai format
|
|
165
|
+
val = decimalPart && !isIDR
|
|
166
|
+
? `${integerPart}.${decimalPart}`
|
|
167
|
+
: integerPart;
|
|
168
|
+
|
|
169
|
+
return currency.replace(/\./g, "") + " " + val;
|
|
154
170
|
},
|
|
155
171
|
/** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/utils.md#numberAbsolute) untuk melihat dokumentasi*/
|
|
156
172
|
numberAbsolute(toNumber: string | number): number {
|