mirror of
https://github.com/flarum/framework.git
synced 2024-11-29 12:43:52 +08:00
parent
894707c61a
commit
7fa4189fc1
|
@ -1,11 +1,13 @@
|
||||||
|
import app from '../../forum/app';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The `formatNumber` utility localizes a number into a string with the
|
* The `formatNumber` utility localizes a number into a string with the
|
||||||
* appropriate punctuation.
|
* appropriate punctuation based on the provided locale otherwise will default to the users locale.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* formatNumber(1234);
|
* formatNumber(1234);
|
||||||
* // 1,234
|
* // 1,234
|
||||||
*/
|
*/
|
||||||
export default function formatNumber(number: number): string {
|
export default function formatNumber(number: number, locale: string = app.data.locale): string {
|
||||||
return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
return new Intl.NumberFormat(locale).format(number);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user