File tree Expand file tree Collapse file tree 1 file changed +13
-8
lines changed
Expand file tree Collapse file tree 1 file changed +13
-8
lines changed Original file line number Diff line number Diff line change @@ -16,16 +16,21 @@ export function localeFormatter(
1616 locale : string | null ,
1717 precision = 2 ,
1818) : ( num : number ) => string {
19+ let f ;
1920 if ( locale == null ) {
20- return format ( `.${ precision . toString ( ) } f` ) ;
21+ f = format ( `.${ precision . toString ( ) } f` ) ;
22+ } else {
23+ // this needs to be between 0 and 20
24+ const digits = Math . max ( 0 , Math . min ( precision , 20 ) ) ;
25+ const fmt = new Intl . NumberFormat ( locale . replace ( "_" , "-" ) , {
26+ minimumFractionDigits : digits ,
27+ maximumFractionDigits : digits ,
28+ } ) ;
29+ f = fmt . format . bind ( fmt ) ;
2130 }
22- // this needs to be between 0 and 20
23- const digits = Math . max ( 0 , Math . min ( precision , 20 ) ) ;
24- const fmt = new Intl . NumberFormat ( locale . replace ( "_" , "-" ) , {
25- minimumFractionDigits : digits ,
26- maximumFractionDigits : digits ,
27- } ) ;
28- return fmt . format . bind ( fmt ) ;
31+
32+ // replace unicode minus sign with ascii hyphen
33+ return ( num ) => f ( num ) . replace ( "−" , "-" ) ;
2934}
3035
3136const formatterPer = format ( ".2f" ) ;
You can’t perform that action at this time.
0 commit comments