@wener/console
Version:
Base console UI toolkit
24 lines (23 loc) • 752 B
JavaScript
import { isDefined } from '@wener/utils';
export function formatAmount(v) {
var _ref = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, currency = _ref.currency, _ref_fallback = _ref.fallback, fallback = _ref_fallback === void 0 ? '-' : _ref_fallback;
if (!isDefined(v)) {
return fallback;
}
if (typeof v === 'string') {
v = Number.parseFloat(v);
}
if (Number.isNaN(v)) {
return fallback;
}
if (currency) {
return new Intl.NumberFormat('zh-CN', {
style: 'currency',
currency: currency
}).format(v);
}
return new Intl.NumberFormat('zh-CN', {
minimumFractionDigits: 2,
maximumFractionDigits: 2
}).format(v);
}