mirror of
https://github.com/flarum/framework.git
synced 2024-11-25 17:57:04 +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
|
||||
* appropriate punctuation.
|
||||
* appropriate punctuation based on the provided locale otherwise will default to the users locale.
|
||||
*
|
||||
* @example
|
||||
* formatNumber(1234);
|
||||
* // 1,234
|
||||
*/
|
||||
export default function formatNumber(number: number): string {
|
||||
return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
||||
export default function formatNumber(number: number, locale: string = app.data.locale): string {
|
||||
return new Intl.NumberFormat(locale).format(number);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user